Skip to content

Commit df50f03

Browse files
authored
feat(fmt): log when formatting starts (#309)
1 parent dcecdb8 commit df50f03

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

packages/rstack/src/fmt/cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
335335
}
336336
}
337337

338-
if (mode === 'check') {
338+
if (mode === 'write') {
339+
logger.start('Formatting...');
340+
} else if (mode === 'check') {
339341
logger.start('Checking formatting...');
340342
}
341343

@@ -350,6 +352,8 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
350352
if (ignoreUnknown) {
351353
if (mode === 'check') {
352354
logger.success('No supported files to check.');
355+
} else if (mode === 'write') {
356+
logger.success('No supported files to format.');
353357
}
354358
return;
355359
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test('returns exit code 2 for formatting errors', () => {
137137
const result = runFmt(['index.ts']);
138138

139139
expect(result.status).toBe(2);
140-
expect(result.stdout).toBe('');
140+
expect(result.stdout).toBe('start Formatting...\n');
141141
expect(result.stderr).toContain('error index.ts: SyntaxError:');
142142
});
143143

@@ -148,7 +148,9 @@ test('reports partial writes when formatting fails', () => {
148148
const result = runFmt(['valid.ts', 'invalid.ts']);
149149

150150
expect(result.status).toBe(2);
151-
expect(normalizeDuration(result.stdout)).toBe('info Formatted 1 of 2 files in <duration>.\n');
151+
expect(normalizeDuration(result.stdout)).toBe(
152+
'start Formatting...\ninfo Formatted 1 of 2 files in <duration>.\n',
153+
);
152154
expect(result.stderr).toContain('error invalid.ts: SyntaxError:');
153155
expect(readProjectFile('valid.ts')).toBe('const value = true;\n');
154156
expect(readProjectFile('invalid.ts')).toBe('const invalid = ;');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const expectWriteSummary = (
3434
const message = writtenCount
3535
? `Formatted ${writtenCount} of ${matchedFileCount} ${files} in <duration>.`
3636
: `Checked ${matchedFileCount} ${files} in <duration>. No changes needed.`;
37-
expect(normalizeDuration(output)).toBe(`success ${message}\n`);
37+
expect(normalizeDuration(output)).toBe(`start Formatting...\nsuccess ${message}\n`);
3838
};
3939

4040
export const setupFmtTest = (): FmtTestHarness => {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ test('ignores unsupported files with --ignore-unknown', () => {
6262
const result = runFmt([...modeArgs, '--ignore-unknown', 'notes.unknown']);
6363

6464
expect(result.status).toBe(0);
65-
expect(result.stdout).toBe(
66-
modeArgs.includes('--check')
67-
? 'start Checking formatting...\nsuccess No supported files to check.\n'
68-
: '',
69-
);
65+
const expectedStdout = modeArgs.includes('--check')
66+
? 'start Checking formatting...\nsuccess No supported files to check.\n'
67+
: modeArgs.includes('--list-different')
68+
? ''
69+
: 'start Formatting...\nsuccess No supported files to format.\n';
70+
expect(result.stdout).toBe(expectedStdout);
7071
expect(result.stderr).toBe('');
7172
}
7273
});
@@ -77,7 +78,7 @@ test('supports -u as an alias for --ignore-unknown', () => {
7778
const result = runFmt(['-u', 'notes.unknown']);
7879

7980
expect(result.status).toBe(0);
80-
expect(result.stdout).toBe('');
81+
expect(result.stdout).toBe('start Formatting...\nsuccess No supported files to format.\n');
8182
expect(result.stderr).toBe('');
8283
});
8384

@@ -95,6 +96,6 @@ test('does not treat unsupported files as unmatched patterns', () => {
9596
const result = runFmt(['--no-error-on-unmatched-pattern', 'notes.unknown']);
9697

9798
expect(result.status).toBe(2);
98-
expect(result.stdout).toBe('');
99+
expect(result.stdout).toBe('start Formatting...\n');
99100
expect(result.stderr).toContain('No supported files matched "notes.unknown"');
100101
});

0 commit comments

Comments
 (0)