Skip to content

Commit 02a14c0

Browse files
rsanchezGerrit0
authored andcommitted
Add internal-first sort strategy
1 parent d26f553 commit 02a14c0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/lib/utils/sort.ts

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const SORT_STRATEGIES = [
1919
"visibility",
2020
"required-first",
2121
"kind",
22+
"internal-first",
2223
] as const;
2324

2425
export type SortStrategy = (typeof SORT_STRATEGIES)[number];
@@ -151,6 +152,9 @@ const sorts: Record<
151152
kind(a, b, { kindSortOrder }) {
152153
return kindSortOrder.indexOf(a.kind) < kindSortOrder.indexOf(b.kind);
153154
},
155+
"internal-first"(a, b) {
156+
return !a.flags.isExternal && b.flags.isExternal;
157+
},
154158
};
155159

156160
export function getSortFunction(opts: Options) {

src/test/utils/sort.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ describe("Sort", () => {
209209
);
210210
});
211211

212+
it("Should sort by internal first", () => {
213+
const arr = [
214+
new DeclarationReflection("a", ReflectionKind.Function),
215+
new DeclarationReflection("b", ReflectionKind.Function),
216+
new DeclarationReflection("c", ReflectionKind.Function),
217+
];
218+
arr[0].setFlag(ReflectionFlag.External, true);
219+
arr[1].setFlag(ReflectionFlag.External, false);
220+
arr[2].setFlag(ReflectionFlag.External, true);
221+
222+
sortReflections(arr, ["internal-first"]);
223+
equal(
224+
arr.map((r) => r.name),
225+
["b", "a", "c"],
226+
);
227+
});
228+
212229
it("Should sort with multiple strategies", () => {
213230
resetReflectionID();
214231
const arr = [

0 commit comments

Comments
 (0)