From 02a14c0a69f7a571c55279507de3498ec1485632 Mon Sep 17 00:00:00 2001 From: Rob Sanchez Date: Mon, 23 Oct 2023 15:55:00 -0400 Subject: [PATCH] Add internal-first sort strategy --- src/lib/utils/sort.ts | 4 ++++ src/test/utils/sort.test.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/lib/utils/sort.ts b/src/lib/utils/sort.ts index 7ef55cc14..5b5cc3e34 100644 --- a/src/lib/utils/sort.ts +++ b/src/lib/utils/sort.ts @@ -19,6 +19,7 @@ export const SORT_STRATEGIES = [ "visibility", "required-first", "kind", + "internal-first", ] as const; export type SortStrategy = (typeof SORT_STRATEGIES)[number]; @@ -151,6 +152,9 @@ const sorts: Record< kind(a, b, { kindSortOrder }) { return kindSortOrder.indexOf(a.kind) < kindSortOrder.indexOf(b.kind); }, + "internal-first"(a, b) { + return !a.flags.isExternal && b.flags.isExternal; + }, }; export function getSortFunction(opts: Options) { diff --git a/src/test/utils/sort.test.ts b/src/test/utils/sort.test.ts index b01740b68..487eac383 100644 --- a/src/test/utils/sort.test.ts +++ b/src/test/utils/sort.test.ts @@ -209,6 +209,23 @@ describe("Sort", () => { ); }); + it("Should sort by internal first", () => { + const arr = [ + new DeclarationReflection("a", ReflectionKind.Function), + new DeclarationReflection("b", ReflectionKind.Function), + new DeclarationReflection("c", ReflectionKind.Function), + ]; + arr[0].setFlag(ReflectionFlag.External, true); + arr[1].setFlag(ReflectionFlag.External, false); + arr[2].setFlag(ReflectionFlag.External, true); + + sortReflections(arr, ["internal-first"]); + equal( + arr.map((r) => r.name), + ["b", "a", "c"], + ); + }); + it("Should sort with multiple strategies", () => { resetReflectionID(); const arr = [