Skip to content

Commit a71bb03

Browse files
authored
Fix sort order alpha (documentationjs#542)
The old code didn't work correctly with regards to making the sort aware of memberof.
1 parent e11c1ab commit a71bb03

5 files changed

+181
-166
lines changed

lib/sort.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,23 @@ module.exports = function sortDocs(comments, options) {
7575
return fixed.concat(unfixed);
7676
};
7777

78+
function compare(a, b) {
79+
return a.localeCompare(b, undefined, {caseFirst: 'upper'});
80+
}
81+
7882
function compareCommentsByName(a, b) {
79-
return a.name.localeCompare(b.name, undefined, {caseFirst: 'upper'});
83+
var rv;
84+
if (a.memberof) {
85+
if (b.memberof) {
86+
rv = compare(a.memberof, b.memberof);
87+
} else {
88+
rv = compare(a.memberof, b.name);
89+
}
90+
} else if (b.memberof) {
91+
rv = compare(a.name, b.memberof);
92+
}
93+
94+
return rv || compare(a.name, b.name);
8095
}
8196

8297
function compareCommentsBySourceLocation(a, b) {

test/fixture/sort-order-alpha.input.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ function b() {}
77
function a() {}
88

99
/** */
10-
class A {
10+
class C {
1111
/** */
12-
y() {}
12+
b() {}
1313
/** */
14-
Y() {}
14+
B() {}
1515
/** */
16-
x() {}
16+
a() {}
1717
/** */
18-
X() {}
18+
A() {}
1919
}
2020

2121
/** */
22-
class B {
22+
class D {
2323
/** */
24-
y() {}
24+
b() {}
2525
/** */
26-
Y() {}
26+
B() {}
2727
/** */
28-
x() {}
28+
a() {}
2929
/** */
30-
X() {}
30+
A() {}
3131
}

0 commit comments

Comments
 (0)