Skip to content

Commit

Permalink
Sort memberof (#1452)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mmomtchev and tmcw authored Jan 30, 2024
1 parent 930edd2 commit e030a3f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
32 changes: 30 additions & 2 deletions __tests__/lib/__snapshots__/sort.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Array [
"sortKey": "c",
},
"kind": "function",
"memberof": "classB",
"memberof": "classA",
"name": "bananas",
},
Object {
Expand Down Expand Up @@ -174,8 +174,36 @@ Array [
"sortKey": "c",
},
"kind": "function",
"memberof": "classB",
"memberof": "classA",
"name": "bananas",
},
]
`;

exports[`sort toc with files absolute path 4`] = `
Array [
Object {
"context": Object {
"sortKey": "c",
},
"kind": "function",
"memberof": "classA",
"name": "bananas",
},
Object {
"context": Object {
"sortKey": "b",
},
"memberof": "classB",
"name": "carrot",
},
Object {
"context": Object {
"sortKey": "a",
},
"kind": "function",
"memberof": "classB",
"name": "apples",
},
]
`;
8 changes: 7 additions & 1 deletion __tests__/lib/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test('sort toc with files absolute path', function () {
context: { sortKey: 'c' },
name: 'bananas',
kind: 'function',
memberof: 'classB'
memberof: 'classA'
};

const snowflake = {
Expand All @@ -159,4 +159,10 @@ test('sort toc with files absolute path', function () {
sortOrder: ['kind', 'alpha']
})
).toMatchSnapshot();

expect(
sort([carrot, apples, bananas], {
sortOrder: ['memberof', 'kind', 'alpha']
})
).toMatchSnapshot();
});
3 changes: 2 additions & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Options:
[boolean] [default: false]
--sort-order The order to sort the documentation, may be
specified multiple times
[choices: "source", "alpha"]
[choices: "source", "alpha", "kind", "memberof"]
[default: "source"]
--resolve Dependency resolution algorithm.
[choices: "browser", "node"] [Standard: "browser"]
Expand Down
2 changes: 1 addition & 1 deletion src/commands/shared_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const sharedInputOptions = {
'sort-order': {
describe: 'The order to sort the documentation',
array: true,
choices: ['source', 'alpha', 'kind', 'access'],
choices: ['source', 'alpha', 'kind', 'access', 'memberof'],
default: ['source']
},
resolve: {
Expand Down
3 changes: 2 additions & 1 deletion src/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ const sortFns = {
alpha: compareCommentsByField.bind(null, 'name'),
source: compareCommentsBySourceLocation,
kind: compareCommentsByField.bind(null, 'kind'),
access: compareCommentsByField.bind(null, 'access')
access: compareCommentsByField.bind(null, 'access'),
memberof: compareCommentsByField.bind(null, 'memberof')
};

function sortComments(comments, sortOrder) {
Expand Down

0 comments on commit e030a3f

Please sign in to comment.