From 4287d7fc1a38288c6c086f288716cb0da311efe8 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 31 Aug 2026 21:59:44 +0800 Subject: [PATCH 1/2] fix(fmt): clarify formatting fix command --- packages/rstack/src/fmt/cli.ts | 4 ++-- packages/rstack/tests/cli/check.test.ts | 4 +++- packages/rstack/tests/cli/fmt/files.test.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/rstack/src/fmt/cli.ts b/packages/rstack/src/fmt/cli.ts index 0eb4e626..8bafad94 100644 --- a/packages/rstack/src/fmt/cli.ts +++ b/packages/rstack/src/fmt/cli.ts @@ -248,9 +248,9 @@ const logFmtResult = ( if (differentCount > 0) { const differentFiles = formatFileCount(differentCount, true); const processedFiles = formatFileCount(processedFileCount); - const checkOption = color.cyan('--check'); + const fmtCommand = color.cyan('rs fmt'); logger.error( - `Formatting issues found in ${differentFiles}. Run without ${checkOption} to fix.`, + `Formatting issues found in ${differentFiles}. Run ${fmtCommand} to fix.`, ); logger.info(`Checked ${processedFiles} in ${prettyTime(durationSeconds)}.`); } else if (result.exitCode === 0) { diff --git a/packages/rstack/tests/cli/check.test.ts b/packages/rstack/tests/cli/check.test.ts index a2b975a9..3d9fce78 100644 --- a/packages/rstack/tests/cli/check.test.ts +++ b/packages/rstack/tests/cli/check.test.ts @@ -36,7 +36,9 @@ test('runs lint followed by a formatting check', () => { expect(unformatted.status).toBe(1); expect(unformatted.stdout).toContain('Checking formatting...'); - expect(unformatted.stderr).toContain('Formatting issues found in 1 file.'); + expect(unformatted.stderr).toContain( + 'Formatting issues found in 1 file. Run rs fmt to fix.', + ); writeProjectFile('src/index.ts', 'const value = true;\n'); const formatted = runCheck(); diff --git a/packages/rstack/tests/cli/fmt/files.test.ts b/packages/rstack/tests/cli/fmt/files.test.ts index f0368df4..b16d7882 100644 --- a/packages/rstack/tests/cli/fmt/files.test.ts +++ b/packages/rstack/tests/cli/fmt/files.test.ts @@ -108,7 +108,7 @@ test('checks formatting without writing files', () => { ); expect(result.stderr).toContain('error index.ts'); expect(normalizeDuration(result.stderr)).toContain( - 'error Formatting issues found in 1 file. Run without --check to fix.', + 'error Formatting issues found in 1 file. Run rs fmt to fix.', ); expect(readProjectFile('index.ts')).toBe(source); From 4db18ba3da13eb3c42608dbfcc0878f9b11e0359 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 31 Aug 2026 22:13:15 +0800 Subject: [PATCH 2/2] fix(fmt): preserve formatting check scope --- packages/rstack/src/cli/commands.ts | 2 +- packages/rstack/src/fmt/cli.ts | 22 +++++++++++++++------ packages/rstack/tests/cli/fmt/files.test.ts | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/rstack/src/cli/commands.ts b/packages/rstack/src/cli/commands.ts index 9970d32e..0c4c1881 100644 --- a/packages/rstack/src/cli/commands.ts +++ b/packages/rstack/src/cli/commands.ts @@ -185,7 +185,7 @@ async function runCheckCLI(args: string[]): Promise { /* rspackChunkName: 'fmt' */ '../fmt/cli.ts' ); - await runFmtCLI(['--check'], { loadedConfig }); + await runFmtCLI(['--check'], { fixCommand: 'rs fmt', loadedConfig }); } export async function setupCommands(): Promise { diff --git a/packages/rstack/src/fmt/cli.ts b/packages/rstack/src/fmt/cli.ts index 8bafad94..ed61c36b 100644 --- a/packages/rstack/src/fmt/cli.ts +++ b/packages/rstack/src/fmt/cli.ts @@ -30,6 +30,8 @@ interface ParsedFmtCLIArgs { } type RunFmtCLIOptions = { + /** Command shown to fix formatting issues found in check mode. */ + fixCommand?: string; /** Rstack config already loaded by the lint phase of `rs check`. */ loadedConfig?: LoadedRstackConfig; }; @@ -206,6 +208,7 @@ const logFmtResult = ( cwd: string, processedFileCount: number, durationSeconds: number, + fixCommand?: string, ): void => { let writtenCount = 0; let differentCount = 0; @@ -248,10 +251,10 @@ const logFmtResult = ( if (differentCount > 0) { const differentFiles = formatFileCount(differentCount, true); const processedFiles = formatFileCount(processedFileCount); - const fmtCommand = color.cyan('rs fmt'); - logger.error( - `Formatting issues found in ${differentFiles}. Run ${fmtCommand} to fix.`, - ); + const fixHint = fixCommand + ? `Run ${color.cyan(fixCommand)} to fix.` + : `Rerun this command without ${color.cyan('--check')} to fix.`; + logger.error(`Formatting issues found in ${differentFiles}. ${fixHint}`); logger.info(`Checked ${processedFiles} in ${prettyTime(durationSeconds)}.`); } else if (result.exitCode === 0) { logger.success( @@ -276,7 +279,7 @@ const loadFmtConfig = async ( const runFmtCLI = async ( args: string[], - { loadedConfig }: RunFmtCLIOptions = {}, + { fixCommand, loadedConfig }: RunFmtCLIOptions = {}, ): Promise => { const cwd = process.cwd(); const startTime = performance.now(); @@ -413,7 +416,14 @@ const runFmtCLI = async ( } const durationSeconds = (performance.now() - startTime) / 1000; - logFmtResult(result, mode, cwd, result.processedFileCount, durationSeconds); + logFmtResult( + result, + mode, + cwd, + result.processedFileCount, + durationSeconds, + fixCommand, + ); process.exitCode = result.exitCode; } catch (error) { logger.error(error); diff --git a/packages/rstack/tests/cli/fmt/files.test.ts b/packages/rstack/tests/cli/fmt/files.test.ts index b16d7882..47208688 100644 --- a/packages/rstack/tests/cli/fmt/files.test.ts +++ b/packages/rstack/tests/cli/fmt/files.test.ts @@ -108,7 +108,7 @@ test('checks formatting without writing files', () => { ); expect(result.stderr).toContain('error index.ts'); expect(normalizeDuration(result.stderr)).toContain( - 'error Formatting issues found in 1 file. Run rs fmt to fix.', + 'error Formatting issues found in 1 file. Rerun this command without --check to fix.', ); expect(readProjectFile('index.ts')).toBe(source);