mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs: sort class properties and methods (#6893)
* docs: sort class properties and methods - Properties are sorted in the order of [Inputs, Outputs, neither]. Secondary sorting done alphabetically. - Methods are sorted alphabetically. - All deprecated members are sorted to the end. * Use the same sort for methods and properties
This commit is contained in:
@@ -43,6 +43,10 @@ module.exports = function categorizer() {
|
||||
|
||||
decoratePublicDoc(classDoc);
|
||||
|
||||
// Sort members
|
||||
classDoc.methods.sort(sortMembers);
|
||||
classDoc.properties.sort(sortMembers);
|
||||
|
||||
// Categorize the current visited classDoc into its Angular type.
|
||||
if (isDirective(classDoc)) {
|
||||
classDoc.isDirective = true;
|
||||
@@ -95,6 +99,40 @@ function filterDuplicateMembers(item, _index, array) {
|
||||
return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item;
|
||||
}
|
||||
|
||||
/** Sorts members by deprecated status, member decorator, and name. */
|
||||
function sortMembers(docA, docB) {
|
||||
// Sort deprecated docs to the end
|
||||
if (!docA.isDeprecated && docB.isDeprecated) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (docA.isDeprecated && !docB.isDeprecated) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Sort in the order of: Inputs, Outputs, neither
|
||||
if ((isDirectiveInput(docA) && !isDirectiveInput(docB)) ||
|
||||
(isDirectiveOutput(docA) && !isDirectiveInput(docB) && !isDirectiveOutput(docB))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((isDirectiveInput(docB) && !isDirectiveInput(docA)) ||
|
||||
(isDirectiveOutput(docB) && !isDirectiveInput(docA) && !isDirectiveOutput(docA))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Break ties by sorting alphabetically on the name
|
||||
if (docA.name < docB.name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (docA.name > docB.name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `parameters` property are the parameters extracted from TypeScript and are strings
|
||||
* of the form "propertyName: propertyType" (literally what's written in the source).
|
||||
|
||||
Reference in New Issue
Block a user