From 4c3b4c492264187349c64e81663a6f0a8717eb1c Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 4 Aug 2026 22:52:43 +0800 Subject: [PATCH] feat(fmt): support --ignorePath --- packages/rstack/src/fmt/cli.ts | 4 +++- packages/rstack/tests/cli/fmt/index.test.ts | 6 +++--- packages/rstack/tests/fmt/cli.test.ts | 10 ++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/rstack/src/fmt/cli.ts b/packages/rstack/src/fmt/cli.ts index 22e3ae8..47e3735 100644 --- a/packages/rstack/src/fmt/cli.ts +++ b/packages/rstack/src/fmt/cli.ts @@ -62,6 +62,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => { 'list-different': { type: 'boolean' }, listDifferent: { type: 'boolean' }, 'ignore-path': { type: 'string', multiple: true }, + ignorePath: { type: 'string', multiple: true }, 'no-error-on-unmatched-pattern': { type: 'boolean' }, noErrorOnUnmatchedPattern: { type: 'boolean' }, 'parallel-workers': { type: 'string' }, @@ -81,6 +82,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => { } const mode = values.check ? 'check' : listDifferent ? 'list-different' : 'write'; + const ignorePaths = [...(values['ignore-path'] ?? []), ...(values.ignorePath ?? [])]; const noErrorOnUnmatchedPattern = values['no-error-on-unmatched-pattern'] ?? values.noErrorOnUnmatchedPattern ?? false; const maxWorkers = parseMaxWorkers(values['parallel-workers'], values.parallelWorkers); @@ -101,7 +103,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => { return { mode, patterns: positionals, - ignorePaths: values['ignore-path'] ?? [], + ignorePaths, noErrorOnUnmatchedPattern, maxWorkers, help: values.help ?? false, diff --git a/packages/rstack/tests/cli/fmt/index.test.ts b/packages/rstack/tests/cli/fmt/index.test.ts index e048934..07391ce 100644 --- a/packages/rstack/tests/cli/fmt/index.test.ts +++ b/packages/rstack/tests/cli/fmt/index.test.ts @@ -195,7 +195,7 @@ test('does not load Prettier config or ignore files', () => { expect(readProjectFile('index.ts')).toBe('function getMessage() {\n return "hello";\n}\n'); }); -test('applies repeated ignore paths to explicit files', () => { +test.each(['--ignore-path', '--ignorePath'])('applies repeated ignore paths with %s', (option) => { writeProjectFile('.prettierignore', 'src/ignored-by-root.ts\n'); writeProjectFile('config/extra.ignore', '../src/ignored-by-extra.ts\n'); writeProjectFile('src/ignored-by-root.ts', 'const root="ignored"'); @@ -203,9 +203,9 @@ test('applies repeated ignore paths to explicit files', () => { writeProjectFile('src/index.ts', 'const index="formatted"'); const result = runFmt([ - '--ignore-path', + option, '.prettierignore', - '--ignore-path=config/extra.ignore', + `${option}=config/extra.ignore`, 'src/ignored-by-root.ts', 'src/ignored-by-extra.ts', 'src/index.ts', diff --git a/packages/rstack/tests/fmt/cli.test.ts b/packages/rstack/tests/fmt/cli.test.ts index bd6339e..3dcf5a9 100644 --- a/packages/rstack/tests/fmt/cli.test.ts +++ b/packages/rstack/tests/fmt/cli.test.ts @@ -99,9 +99,15 @@ test.each(['--help', '-h'])('parses %s', (option) => { expect(parseFmtCLIArgs([option]).help).toBe(true); }); -test('collects repeated ignore paths', () => { +test.each(['--ignore-path', '--ignorePath'])('collects repeated ignore paths with %s', (option) => { expect( - parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignore-path=config/format.ignore']) + parseFmtCLIArgs([option, '.prettierignore', `${option}=config/format.ignore`]).ignorePaths, + ).toEqual(['.prettierignore', 'config/format.ignore']); +}); + +test('combines kebab-case and camel-case ignore paths', () => { + expect( + parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignorePath', 'config/format.ignore']) .ignorePaths, ).toEqual(['.prettierignore', 'config/format.ignore']); });