Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/rstack/src/fmt/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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);
Expand All @@ -101,7 +103,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
return {
mode,
patterns: positionals,
ignorePaths: values['ignore-path'] ?? [],
ignorePaths,
noErrorOnUnmatchedPattern,
maxWorkers,
help: values.help ?? false,
Expand Down
6 changes: 3 additions & 3 deletions packages/rstack/tests/cli/fmt/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ 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"');
writeProjectFile('src/ignored-by-extra.ts', 'const extra="ignored"');
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',
Expand Down
10 changes: 8 additions & 2 deletions packages/rstack/tests/fmt/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
Expand Down