Skip to content

Commit 9f2fd47

Browse files
willshowelltinayuangao
authored andcommitted
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
1 parent ab20ffd commit 9f2fd47

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tools/dgeni/processors/categorizer.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ module.exports = function categorizer() {
4343

4444
decoratePublicDoc(classDoc);
4545

46+
// Sort members
47+
classDoc.methods.sort(sortMembers);
48+
classDoc.properties.sort(sortMembers);
49+
4650
// Categorize the current visited classDoc into its Angular type.
4751
if (isDirective(classDoc)) {
4852
classDoc.isDirective = true;
@@ -95,6 +99,40 @@ function filterDuplicateMembers(item, _index, array) {
9599
return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item;
96100
}
97101

102+
/** Sorts members by deprecated status, member decorator, and name. */
103+
function sortMembers(docA, docB) {
104+
// Sort deprecated docs to the end
105+
if (!docA.isDeprecated && docB.isDeprecated) {
106+
return -1;
107+
}
108+
109+
if (docA.isDeprecated && !docB.isDeprecated) {
110+
return 1;
111+
}
112+
113+
// Sort in the order of: Inputs, Outputs, neither
114+
if ((isDirectiveInput(docA) && !isDirectiveInput(docB)) ||
115+
(isDirectiveOutput(docA) && !isDirectiveInput(docB) && !isDirectiveOutput(docB))) {
116+
return -1;
117+
}
118+
119+
if ((isDirectiveInput(docB) && !isDirectiveInput(docA)) ||
120+
(isDirectiveOutput(docB) && !isDirectiveInput(docA) && !isDirectiveOutput(docA))) {
121+
return 1;
122+
}
123+
124+
// Break ties by sorting alphabetically on the name
125+
if (docA.name < docB.name) {
126+
return -1;
127+
}
128+
129+
if (docA.name > docB.name) {
130+
return 1;
131+
}
132+
133+
return 0;
134+
}
135+
98136
/**
99137
* The `parameters` property are the parameters extracted from TypeScript and are strings
100138
* of the form "propertyName: propertyType" (literally what's written in the source).

0 commit comments

Comments
 (0)