Skip to content

Commit 56b735a

Browse files
committed
fix(fmt): error when no files match
1 parent dd1070a commit 56b735a

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎packages/rstack/src/fmt/cli.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
243243
});
244244

245245
if (files.length === 0) {
246-
if (mode !== 'list-different') {
247-
logger.info('No files matched.');
248-
}
246+
const targets = (patterns.length ? patterns : ['.'])
247+
.map((pattern) => color.cyan(JSON.stringify(pattern)))
248+
.join(', ');
249+
logger.error(`No supported files matched ${targets}, or all matching files were ignored.`);
250+
process.exitCode = 2;
249251
return;
250252
}
251253

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,15 @@ test('writes nothing for empty stdin', () => {
585585
expect(result.stderr).toBe('');
586586
});
587587

588-
test('reports when no files match', () => {
589-
const writeResult = runFmt(['missing/**/*.ts']);
588+
test('returns exit code 2 when no files match', () => {
589+
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
590+
const result = runFmt([...modeArgs, 'missing/**/*.ts']);
590591

591-
expect(writeResult.status).toBe(0);
592-
expect(writeResult.stdout).toBe('info No files matched.\n');
593-
expect(writeResult.stderr).toBe('');
594-
595-
const checkResult = runFmt(['--check', 'missing/**/*.ts']);
596-
597-
expect(checkResult.status).toBe(0);
598-
expect(checkResult.stdout).toBe('info No files matched.\n');
599-
expect(checkResult.stderr).toBe('');
592+
expect(result.status).toBe(2);
593+
expect(result.stdout).toBe('');
594+
expect(result.stderr).toContain(
595+
'No supported files matched "missing/**/*.ts", or all matching files were ignored.',
596+
);
597+
expect(result.stderr).not.toContain('\n at ');
598+
}
600599
});

0 commit comments

Comments
 (0)