Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs: sort all enums in doclint (#3488)

Dmitry Gozman5aa4116204f0
diff --git a/utils/doclint/check_public_api/JSBuilder.js b/utils/doclint/check_public_api/JSBuilder.js
index b287e1233f..0c01f47100 100644
--- a/utils/doclint/check_public_api/JSBuilder.js
+++ b/utils/doclint/check_public_api/JSBuilder.js
@@ -197,11 +197,16 @@ function checkSources(sources) {
return new Documentation.Type('Object', properties);
}
if (type.isUnion() && (typeName.includes('|') || type.types.every(type => type.isStringLiteral() || type.intrinsicName === 'number'))) {
- const types = type.types
- .filter(isNotUndefined)
- .map(type => serializeType(type, circular));
- const name = types.map(type => type.name).join('|');
- const properties = [].concat(...types.map(type => type.properties));
+ const types = type.types.filter(isNotUndefined).map((type, index) => {
+ return { isLiteral: type.isStringLiteral(), serialized: serializeType(type, circular), index };
+ });
+ types.sort((a, b) => {
+ if (!a.isLiteral || !b.isLiteral)
+ return a.index - b.index;
+ return a.serialized.name.localeCompare(b.serialized.name);
+ });
+ const name = types.map(type => type.serialized.name).join('|');
+ const properties = [].concat(...types.map(type => type.serialized.properties));
return new Documentation.Type(name.replace(/false\|true/g, 'boolean'), properties);
}
if (type.typeArguments && type.symbol) {
diff --git a/utils/doclint/check_public_api/MDBuilder.js b/utils/doclint/check_public_api/MDBuilder.js
index 7899b93e4c..3179dca194 100644
--- a/utils/doclint/check_public_api/MDBuilder.js
+++ b/utils/doclint/check_public_api/MDBuilder.js
@@ -53,7 +53,12 @@ class MDOutline {
const ul = clone.querySelector(':scope > ul');
const str = parseComment(extractSiblingsIntoFragment(clone.firstChild, ul));
const name = str.substring(0, str.indexOf('<')).replace(/\`/g, '').trim();
- const type = findType(str);
+ let type = findType(str);
+ const literals = type.match(/("[^"]+"(\|"[^"]+")*)/);
+ if (literals) {
+ const sorted = literals[1].split('|').sort((a, b) => a.localeCompare(b)).join('|');
+ type = type.substring(0, literals.index) + sorted + type.substring(literals.index + literals[0].length);
+ }
const properties = [];
let comment = str.substring(str.indexOf('<') + type.length + 2).trim();
const hasNonEnumProperties = type.split('|').some(part => {