Skip to content

Commit e030a3f

Browse files
mmomtchevtmcw
andauthored
Sort memberof (#1452)
* correctly sort undefined values * the new sort order is the correct one * support sorting by memberof * support sorting by memberof --------- Co-authored-by: Tom MacWright <tmcw@users.noreply.github.com>
1 parent 930edd2 commit e030a3f

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

__tests__/lib/__snapshots__/sort.js.snap

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Array [
139139
"sortKey": "c",
140140
},
141141
"kind": "function",
142-
"memberof": "classB",
142+
"memberof": "classA",
143143
"name": "bananas",
144144
},
145145
Object {
@@ -174,8 +174,36 @@ Array [
174174
"sortKey": "c",
175175
},
176176
"kind": "function",
177-
"memberof": "classB",
177+
"memberof": "classA",
178+
"name": "bananas",
179+
},
180+
]
181+
`;
182+
183+
exports[`sort toc with files absolute path 4`] = `
184+
Array [
185+
Object {
186+
"context": Object {
187+
"sortKey": "c",
188+
},
189+
"kind": "function",
190+
"memberof": "classA",
178191
"name": "bananas",
179192
},
193+
Object {
194+
"context": Object {
195+
"sortKey": "b",
196+
},
197+
"memberof": "classB",
198+
"name": "carrot",
199+
},
200+
Object {
201+
"context": Object {
202+
"sortKey": "a",
203+
},
204+
"kind": "function",
205+
"memberof": "classB",
206+
"name": "apples",
207+
},
180208
]
181209
`;

__tests__/lib/sort.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ test('sort toc with files absolute path', function () {
141141
context: { sortKey: 'c' },
142142
name: 'bananas',
143143
kind: 'function',
144-
memberof: 'classB'
144+
memberof: 'classA'
145145
};
146146

147147
const snowflake = {
@@ -159,4 +159,10 @@ test('sort toc with files absolute path', function () {
159159
sortOrder: ['kind', 'alpha']
160160
})
161161
).toMatchSnapshot();
162+
163+
expect(
164+
sort([carrot, apples, bananas], {
165+
sortOrder: ['memberof', 'kind', 'alpha']
166+
})
167+
).toMatchSnapshot();
162168
});

docs/USAGE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Options:
6363
[boolean] [default: false]
6464
--sort-order The order to sort the documentation, may be
6565
specified multiple times
66-
[choices: "source", "alpha"]
66+
[choices: "source", "alpha", "kind", "memberof"]
67+
6768
[default: "source"]
6869
--resolve Dependency resolution algorithm.
6970
[choices: "browser", "node"] [Standard: "browser"]

src/commands/shared_options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const sharedInputOptions = {
7575
'sort-order': {
7676
describe: 'The order to sort the documentation',
7777
array: true,
78-
choices: ['source', 'alpha', 'kind', 'access'],
78+
choices: ['source', 'alpha', 'kind', 'access', 'memberof'],
7979
default: ['source']
8080
},
8181
resolve: {

src/sort.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ const sortFns = {
123123
alpha: compareCommentsByField.bind(null, 'name'),
124124
source: compareCommentsBySourceLocation,
125125
kind: compareCommentsByField.bind(null, 'kind'),
126-
access: compareCommentsByField.bind(null, 'access')
126+
access: compareCommentsByField.bind(null, 'access'),
127+
memberof: compareCommentsByField.bind(null, 'memberof')
127128
};
128129

129130
function sortComments(comments, sortOrder) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy