Skip to content

Commit afb7bbf

Browse files
authored
feat(fmt): support --ignorePath (#180)
1 parent bb1ac5c commit afb7bbf

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

packages/rstack/src/fmt/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
6262
'list-different': { type: 'boolean' },
6363
listDifferent: { type: 'boolean' },
6464
'ignore-path': { type: 'string', multiple: true },
65+
ignorePath: { type: 'string', multiple: true },
6566
'no-error-on-unmatched-pattern': { type: 'boolean' },
6667
noErrorOnUnmatchedPattern: { type: 'boolean' },
6768
'parallel-workers': { type: 'string' },
@@ -81,6 +82,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
8182
}
8283

8384
const mode = values.check ? 'check' : listDifferent ? 'list-different' : 'write';
85+
const ignorePaths = [...(values['ignore-path'] ?? []), ...(values.ignorePath ?? [])];
8486
const noErrorOnUnmatchedPattern =
8587
values['no-error-on-unmatched-pattern'] ?? values.noErrorOnUnmatchedPattern ?? false;
8688
const maxWorkers = parseMaxWorkers(values['parallel-workers'], values.parallelWorkers);
@@ -101,7 +103,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
101103
return {
102104
mode,
103105
patterns: positionals,
104-
ignorePaths: values['ignore-path'] ?? [],
106+
ignorePaths,
105107
noErrorOnUnmatchedPattern,
106108
maxWorkers,
107109
help: values.help ?? false,

packages/rstack/tests/cli/fmt/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ test('does not load Prettier config or ignore files', () => {
195195
expect(readProjectFile('index.ts')).toBe('function getMessage() {\n return "hello";\n}\n');
196196
});
197197

198-
test('applies repeated ignore paths to explicit files', () => {
198+
test.each(['--ignore-path', '--ignorePath'])('applies repeated ignore paths with %s', (option) => {
199199
writeProjectFile('.prettierignore', 'src/ignored-by-root.ts\n');
200200
writeProjectFile('config/extra.ignore', '../src/ignored-by-extra.ts\n');
201201
writeProjectFile('src/ignored-by-root.ts', 'const root="ignored"');
202202
writeProjectFile('src/ignored-by-extra.ts', 'const extra="ignored"');
203203
writeProjectFile('src/index.ts', 'const index="formatted"');
204204

205205
const result = runFmt([
206-
'--ignore-path',
206+
option,
207207
'.prettierignore',
208-
'--ignore-path=config/extra.ignore',
208+
`${option}=config/extra.ignore`,
209209
'src/ignored-by-root.ts',
210210
'src/ignored-by-extra.ts',
211211
'src/index.ts',

packages/rstack/tests/fmt/cli.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,15 @@ test.each(['--help', '-h'])('parses %s', (option) => {
9999
expect(parseFmtCLIArgs([option]).help).toBe(true);
100100
});
101101

102-
test('collects repeated ignore paths', () => {
102+
test.each(['--ignore-path', '--ignorePath'])('collects repeated ignore paths with %s', (option) => {
103103
expect(
104-
parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignore-path=config/format.ignore'])
104+
parseFmtCLIArgs([option, '.prettierignore', `${option}=config/format.ignore`]).ignorePaths,
105+
).toEqual(['.prettierignore', 'config/format.ignore']);
106+
});
107+
108+
test('combines kebab-case and camel-case ignore paths', () => {
109+
expect(
110+
parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignorePath', 'config/format.ignore'])
105111
.ignorePaths,
106112
).toEqual(['.prettierignore', 'config/format.ignore']);
107113
});

0 commit comments

Comments
 (0)