docs: sort all enums in doclint (#3488)

Currently, the order depends on some internals of typescript compiler
and changes from time to time. Sorting makes it stable.
This commit is contained in:
Dmitry Gozman 2020-08-17 10:47:21 -07:00 committed by GitHub
parent 3aae8c6be1
commit 5aa4116204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -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) {

View File

@ -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 => {