Skip to content

Accept readonly arrays in detect order option - #51

Merged
bluwy merged 1 commit into
mainfrom
readonly-detect-order
Oct 23, 2026
Merged

bluwy merged 1 commit into
mainfrom
readonly-detect-order

Conversation

@Andarist

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/detect.ts
* @default ["dprint", "deno", "oxfmt", "biome", "prettier"] // from `defaultDetectOrder`
*/
order?: FormatterName[];
order?: readonly FormatterName[];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will break mutable arrays tho, in case we need to filter later again

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both are OK:

type Formatter = "dprint" | "deno" | "oxfmt" | "biome" | "prettier";

declare function test(options: { formatters?: readonly Formatter[] }): void;

declare const ro: readonly Formatter[];
declare const mutable: Formatter[];

test({
  formatters: ro, // ok
});
test({
  formatters: mutable, // ok
});

Internally we can always make a copy if needed, we shouldn't mutate the input array anyway.

@bluwy
bluwy added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit e3a963c Oct 23, 2026
10 checks passed
@bluwy
bluwy deleted the readonly-detect-order branch October 23, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants