From e074e6979b9b23e14a91917159c1770cb96bf1a4 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 9 Oct 2026 17:07:46 +0800 Subject: [PATCH 1/5] fix: run formatting checks after lint errors --- packages/rstack/src/cli/commands.ts | 7 +++- packages/rstack/tests/cli/check.test.ts | 46 +++++++++++++++++++++++-- website/docs/en/guide/cli/check.mdx | 20 +++-------- website/docs/zh/guide/cli/check.mdx | 20 +++-------- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/packages/rstack/src/cli/commands.ts b/packages/rstack/src/cli/commands.ts index 75df4237..5080514b 100644 --- a/packages/rstack/src/cli/commands.ts +++ b/packages/rstack/src/cli/commands.ts @@ -187,7 +187,8 @@ async function runCheckCLI(args: string[]): Promise { ...(values.typeCheck ? ['--type-check'] : []), ...fileArgs, ]); - if (process.exitCode) { + const lintExitCode = Number(process.exitCode ?? 0); + if (values.fix && lintExitCode !== 0) { return; } @@ -200,10 +201,14 @@ async function runCheckCLI(args: string[]): Promise { /* rspackChunkName: 'fmt' */ '../fmt/cli.ts' ); + // Keep each phase's status separate: fmt may succeed or return without + // setting an exit code, but neither should clear a lint failure. + process.exitCode = 0; await runFmtCLI([values.fix ? '--write' : '--check', ...fileArgs], { fixOption: '--fix', loadedConfig, }); + process.exitCode = Math.max(lintExitCode, Number(process.exitCode ?? 0)); } export async function setupCommands(): Promise { diff --git a/packages/rstack/tests/cli/check.test.ts b/packages/rstack/tests/cli/check.test.ts index bfc544e3..d7b0e3f4 100644 --- a/packages/rstack/tests/cli/check.test.ts +++ b/packages/rstack/tests/cli/check.test.ts @@ -165,17 +165,57 @@ test('enables type checking only with --type-check', () => { expect(`${withTypeCheck.stdout}\n${withTypeCheck.stderr}`).toContain( 'TS2322', ); + expect(withTypeCheck.stdout).toContain('Format check passed in'); }); -test('does not run the formatting check when lint fails', () => { +test.each([ + { source: 'debugger;\n', formatted: true }, + { source: 'debugger;const value=true', formatted: false }, +])( + 'checks formatting after lint fails (formatted: $formatted)', + ({ source, formatted }) => { + writeLintConfig(); + writeProjectFile('src/index.js', source); + + const result = runCheck(['src/index.js']); + + expect(result.status).toBe(1); + expect(`${result.stdout}\n${result.stderr}`).toContain( + "Unexpected 'debugger' statement", + ); + if (formatted) { + expect(result.stdout).toContain('Format check passed in'); + } else { + expect(result.stderr).toContain('Formatting issues found in 1 file.'); + } + expect(readProjectFile('src/index.js')).toBe(source); + }, +); + +test('preserves a formatter error exit code after lint fails', () => { writeLintConfig(); writeProjectFile('src/index.js', 'debugger;\n'); + writeProjectFile('src/broken.json', '{ "value": }'); + + const result = runCheck(['src']); + + expect(result.status).toBe(2); + expect(`${result.stdout}\n${result.stderr}`).toContain( + "Unexpected 'debugger' statement", + ); + expect(result.stderr).toContain('broken.json'); +}); + +test('does not format when lint fails in fix mode', () => { + writeLintConfig(); + writeProjectFile('src/index.js', 'debugger;const value=true'); - const result = runCheck(); + const result = runCheck(['--fix', 'src/index.js']); expect(result.status).toBe(1); expect(`${result.stdout}\n${result.stderr}`).toContain( "Unexpected 'debugger' statement", ); - expect(result.stdout).not.toContain('Checking formatting...'); + expect(result.stdout).not.toContain('Formatting...'); + expect(readProjectFile('src/index.js')).toBe('debugger;const value=true'); }); diff --git a/website/docs/en/guide/cli/check.mdx b/website/docs/en/guide/cli/check.mdx index 871fc3cf..391a8f8e 100644 --- a/website/docs/en/guide/cli/check.mdx +++ b/website/docs/en/guide/cli/check.mdx @@ -18,21 +18,13 @@ Pass files or directories to limit both linting and formatting to those paths: rs check src/index.ts packages/utils ``` -The same file arguments are passed to both commands, so the example above is equivalent to: - -```bash -rs lint src/index.ts packages/utils && rs fmt --check src/index.ts packages/utils -``` +The same file arguments are passed to both linting and formatting. ## Checks -Running `rs check` is equivalent to: - -```bash -rs lint && rs fmt --check -``` +Checks run sequentially: linting first, then formatting. Without `--fix`, formatting is checked even when linting or type checking reports errors, so one run reports both sets of problems. The command exits successfully only when every enabled check passes. -Checks run sequentially. If linting fails, `rs check` stops without running the formatting check. The command exits successfully only when every enabled check passes. +Errors that prevent checks from running, such as a configuration that cannot be loaded, can stop the command early. ## Options @@ -60,11 +52,7 @@ Enable TypeScript type checking as part of linting: rs check --type-check ``` -This is equivalent to: - -```bash -rs lint --type-check && rs fmt --check -``` +Formatting is still checked when type checking reports errors, unless `--fix` is also enabled. Type checking is disabled when this option is omitted. diff --git a/website/docs/zh/guide/cli/check.mdx b/website/docs/zh/guide/cli/check.mdx index 0d766a4a..7cc6a908 100644 --- a/website/docs/zh/guide/cli/check.mdx +++ b/website/docs/zh/guide/cli/check.mdx @@ -18,21 +18,13 @@ rs check [options] [files...] rs check src/index.ts packages/utils ``` -相同的文件参数会同时传给两个命令,因此上述示例等同于: - -```bash -rs lint src/index.ts packages/utils && rs fmt --check src/index.ts packages/utils -``` +相同的文件参数会同时传给 lint 和格式检查。 ## 检查内容 \{#checks} -运行 `rs check` 等同于: - -```bash -rs lint && rs fmt --check -``` +各项检查会按顺序运行:先 lint,再检查格式。未启用 `--fix` 时,即使 lint 或类型检查报告错误,也会继续检查格式,在一次运行中报告两类问题。只有所有已启用的检查均通过时,该命令才会成功退出。 -各项检查会按顺序运行。如果 lint 失败,`rs check` 会停止运行,不再检查格式。只有所有已启用的检查均通过时,该命令才会成功退出。 +如果遇到无法加载配置等导致检查无法运行的错误,命令可能会提前停止。 ## 选项 \{#options} @@ -60,11 +52,7 @@ rs lint --fix && rs fmt --write rs check --type-check ``` -该命令等同于: - -```bash -rs lint --type-check && rs fmt --check -``` +类型检查报告错误时,仍会继续检查格式,除非同时启用了 `--fix`。 省略此选项时,不会运行类型检查。 From 6fdd802683f7192b5e52524d700f25374c1d5236 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 9 Oct 2026 18:49:01 +0800 Subject: [PATCH 2/5] style: separate check execution phases --- packages/rstack/src/cli/commands.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/rstack/src/cli/commands.ts b/packages/rstack/src/cli/commands.ts index 5080514b..c42f1cc2 100644 --- a/packages/rstack/src/cli/commands.ts +++ b/packages/rstack/src/cli/commands.ts @@ -187,6 +187,7 @@ async function runCheckCLI(args: string[]): Promise { ...(values.typeCheck ? ['--type-check'] : []), ...fileArgs, ]); + const lintExitCode = Number(process.exitCode ?? 0); if (values.fix && lintExitCode !== 0) { return; @@ -201,13 +202,16 @@ async function runCheckCLI(args: string[]): Promise { /* rspackChunkName: 'fmt' */ '../fmt/cli.ts' ); + // Keep each phase's status separate: fmt may succeed or return without // setting an exit code, but neither should clear a lint failure. process.exitCode = 0; + await runFmtCLI([values.fix ? '--write' : '--check', ...fileArgs], { fixOption: '--fix', loadedConfig, }); + process.exitCode = Math.max(lintExitCode, Number(process.exitCode ?? 0)); } From 70af0341a6e07e7f92fd00294464b43859cc1f45 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 9 Oct 2026 18:51:37 +0800 Subject: [PATCH 3/5] docs: clarify check execution and fix behavior --- website/docs/en/guide/cli/check.mdx | 20 +++++--------------- website/docs/zh/guide/cli/check.mdx | 22 ++++++---------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/website/docs/en/guide/cli/check.mdx b/website/docs/en/guide/cli/check.mdx index 391a8f8e..10d21f74 100644 --- a/website/docs/en/guide/cli/check.mdx +++ b/website/docs/en/guide/cli/check.mdx @@ -4,7 +4,7 @@ description: 'Run linting and formatting checks together, with optional TypeScri # check -The `rs check` command combines linting, formatting, and optional TypeScript type checking for the current project. By default, it runs [`rs lint`](./lint) followed by [`rs fmt --check`](./fmt#--check). +The `rs check` command runs lint and formatting checks for the current project, with optional TypeScript type checking. ## Usage @@ -18,13 +18,11 @@ Pass files or directories to limit both linting and formatting to those paths: rs check src/index.ts packages/utils ``` -The same file arguments are passed to both linting and formatting. - ## Checks -Checks run sequentially: linting first, then formatting. Without `--fix`, formatting is checked even when linting or type checking reports errors, so one run reports both sets of problems. The command exits successfully only when every enabled check passes. +By default, `rs check` runs [`rs lint`](./lint) followed by [`rs fmt --check`](./fmt#--check) without modifying your files. It continues to check formatting even if linting or type checking reports errors, so you can see the results of all enabled checks in one run. -Errors that prevent checks from running, such as a configuration that cannot be loaded, can stop the command early. +The command exits successfully only when all enabled checks pass. Errors that prevent a check from running, such as a failure to load the configuration, may stop the command early. ## Options @@ -36,13 +34,7 @@ Automatically fix linting and formatting issues: rs check --fix ``` -This is equivalent to: - -```bash -rs lint --fix && rs fmt --write -``` - -If linting still fails after applying available fixes, `rs check` stops without running the formatter. +This runs `rs lint --fix` to apply available lint fixes. If linting and any enabled type checking pass, it then runs `rs fmt --write` to format the updated files. ### `--type-check` @@ -52,9 +44,7 @@ Enable TypeScript type checking as part of linting: rs check --type-check ``` -Formatting is still checked when type checking reports errors, unless `--fix` is also enabled. - -Type checking is disabled when this option is omitted. +Type checking is disabled by default. ### `-h, --help` diff --git a/website/docs/zh/guide/cli/check.mdx b/website/docs/zh/guide/cli/check.mdx index 7cc6a908..8cbe54af 100644 --- a/website/docs/zh/guide/cli/check.mdx +++ b/website/docs/zh/guide/cli/check.mdx @@ -1,10 +1,10 @@ --- -description: '同时运行 lint 和格式检查,并可选启用 TypeScript 类型检查。' +description: '统一运行 lint 和格式检查,并可选启用 TypeScript 类型检查。' --- # check -`rs check` 命令可统一运行当前项目的 lint、格式和可选的 TypeScript 类型检查。默认情况下,它会先运行 [`rs lint`](./lint),再运行 [`rs fmt --check`](./fmt#--check)。 +`rs check` 命令用于检查当前项目的 lint 和格式问题,也可以启用 TypeScript 类型检查。 ## 用法 \{#usage} @@ -18,13 +18,11 @@ rs check [options] [files...] rs check src/index.ts packages/utils ``` -相同的文件参数会同时传给 lint 和格式检查。 - ## 检查内容 \{#checks} -各项检查会按顺序运行:先 lint,再检查格式。未启用 `--fix` 时,即使 lint 或类型检查报告错误,也会继续检查格式,在一次运行中报告两类问题。只有所有已启用的检查均通过时,该命令才会成功退出。 +默认情况下,`rs check` 会先运行 [`rs lint`](./lint),再运行 [`rs fmt --check`](./fmt#--check),不会修改文件。即使 lint 或类型检查报告错误,也会继续检查格式,让你在一次运行中看到所有已启用检查的结果。 -如果遇到无法加载配置等导致检查无法运行的错误,命令可能会提前停止。 +只有所有已启用的检查都通过,命令才会成功退出。如果遇到配置加载失败等导致检查无法运行的错误,命令可能会提前停止。 ## 选项 \{#options} @@ -36,13 +34,7 @@ rs check src/index.ts packages/utils rs check --fix ``` -该命令等同于: - -```bash -rs lint --fix && rs fmt --write -``` - -如果应用可用的修复后 lint 仍然失败,`rs check` 会停止运行,不再执行格式化。 +该选项会先运行 `rs lint --fix`,应用可用的 lint 修复。只有 lint 和已启用的类型检查都通过,才会继续运行 `rs fmt --write`,格式化修复后的文件。 ### `--type-check` @@ -52,9 +44,7 @@ rs lint --fix && rs fmt --write rs check --type-check ``` -类型检查报告错误时,仍会继续检查格式,除非同时启用了 `--fix`。 - -省略此选项时,不会运行类型检查。 +默认不启用类型检查。 ### `-h, --help` From ea03a1239ac816cf25c96774bfa429018036b7dd Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 9 Oct 2026 18:54:13 +0800 Subject: [PATCH 4/5] docs: integrate type-check default into option description --- website/docs/en/guide/cli/check.mdx | 4 +--- website/docs/zh/guide/cli/check.mdx | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/website/docs/en/guide/cli/check.mdx b/website/docs/en/guide/cli/check.mdx index 10d21f74..3d267776 100644 --- a/website/docs/en/guide/cli/check.mdx +++ b/website/docs/en/guide/cli/check.mdx @@ -38,14 +38,12 @@ This runs `rs lint --fix` to apply available lint fixes. If linting and any enab ### `--type-check` -Enable TypeScript type checking as part of linting: +By default, `rs check` checks only lint and formatting issues. Add `--type-check` to also check TypeScript types during linting: ```bash rs check --type-check ``` -Type checking is disabled by default. - ### `-h, --help` Display usage and option information without running checks: diff --git a/website/docs/zh/guide/cli/check.mdx b/website/docs/zh/guide/cli/check.mdx index 8cbe54af..bff143f2 100644 --- a/website/docs/zh/guide/cli/check.mdx +++ b/website/docs/zh/guide/cli/check.mdx @@ -38,14 +38,12 @@ rs check --fix ### `--type-check` -在 lint 过程中启用 TypeScript 类型检查: +默认情况下,`rs check` 只检查 lint 和格式问题。添加 `--type-check` 可在 lint 过程中同时检查 TypeScript 类型: ```bash rs check --type-check ``` -默认不启用类型检查。 - ### `-h, --help` 显示命令用法和选项信息,但不运行检查: From e35957693f626bddbbf2f09d2b8b3b422bbbc69c Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 9 Oct 2026 18:56:28 +0800 Subject: [PATCH 5/5] docs: simplify check command guidance --- website/docs/en/guide/cli/check.mdx | 10 +++++----- website/docs/zh/guide/cli/check.mdx | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/website/docs/en/guide/cli/check.mdx b/website/docs/en/guide/cli/check.mdx index 3d267776..4e078c5f 100644 --- a/website/docs/en/guide/cli/check.mdx +++ b/website/docs/en/guide/cli/check.mdx @@ -20,9 +20,9 @@ rs check src/index.ts packages/utils ## Checks -By default, `rs check` runs [`rs lint`](./lint) followed by [`rs fmt --check`](./fmt#--check) without modifying your files. It continues to check formatting even if linting or type checking reports errors, so you can see the results of all enabled checks in one run. +By default, `rs check` runs [`rs lint`](./lint) followed by [`rs fmt --check`](./fmt#--check). It reports issues without modifying files. -The command exits successfully only when all enabled checks pass. Errors that prevent a check from running, such as a failure to load the configuration, may stop the command early. +Formatting is still checked if linting or type checking reports errors. The command exits successfully only when all enabled checks pass. ## Options @@ -34,11 +34,11 @@ Automatically fix linting and formatting issues: rs check --fix ``` -This runs `rs lint --fix` to apply available lint fixes. If linting and any enabled type checking pass, it then runs `rs fmt --write` to format the updated files. +This first runs `rs lint --fix` to apply available lint fixes. If linting and any enabled type checking pass, it then runs `rs fmt --write` to format the updated files. ### `--type-check` -By default, `rs check` checks only lint and formatting issues. Add `--type-check` to also check TypeScript types during linting: +Add `--type-check` to enable TypeScript type checking alongside linting: ```bash rs check --type-check @@ -54,4 +54,4 @@ rs check --help ## Configuration -`rs check` has no separate `define.check()` configuration. It uses the linting configuration from [`define.lint()`](../configuration#define-lint) and the formatting configuration from [`define.fmt()`](../configuration#define-fmt). +`rs check` uses the linting configuration from [`define.lint()`](../configuration#define-lint) and the formatting configuration from [`define.fmt()`](../configuration#define-fmt). diff --git a/website/docs/zh/guide/cli/check.mdx b/website/docs/zh/guide/cli/check.mdx index bff143f2..28b26b06 100644 --- a/website/docs/zh/guide/cli/check.mdx +++ b/website/docs/zh/guide/cli/check.mdx @@ -12,7 +12,7 @@ description: '统一运行 lint 和格式检查,并可选启用 TypeScript 类 rs check [options] [files...] ``` -传入文件或目录,可以将 lint 和格式检查都限制在这些路径中: +传入文件或目录,可以只检查指定路径下的 lint 和格式问题: ```bash rs check src/index.ts packages/utils @@ -20,9 +20,9 @@ rs check src/index.ts packages/utils ## 检查内容 \{#checks} -默认情况下,`rs check` 会先运行 [`rs lint`](./lint),再运行 [`rs fmt --check`](./fmt#--check),不会修改文件。即使 lint 或类型检查报告错误,也会继续检查格式,让你在一次运行中看到所有已启用检查的结果。 +默认情况下,`rs check` 会先运行 [`rs lint`](./lint),再运行 [`rs fmt --check`](./fmt#--check),仅报告问题,不修改文件。 -只有所有已启用的检查都通过,命令才会成功退出。如果遇到配置加载失败等导致检查无法运行的错误,命令可能会提前停止。 +即使 lint 或类型检查报告错误,也会继续检查格式。只有所有已启用的检查都通过,命令才会成功退出。 ## 选项 \{#options} @@ -34,11 +34,11 @@ rs check src/index.ts packages/utils rs check --fix ``` -该选项会先运行 `rs lint --fix`,应用可用的 lint 修复。只有 lint 和已启用的类型检查都通过,才会继续运行 `rs fmt --write`,格式化修复后的文件。 +该选项会先运行 `rs lint --fix`,自动修复 lint 问题。只有 lint 和已启用的类型检查都通过,才会继续运行 `rs fmt --write`,格式化修复后的文件。 ### `--type-check` -默认情况下,`rs check` 只检查 lint 和格式问题。添加 `--type-check` 可在 lint 过程中同时检查 TypeScript 类型: +添加 `--type-check`,可在 lint 过程中启用 TypeScript 类型检查: ```bash rs check --type-check @@ -54,4 +54,4 @@ rs check --help ## 配置 \{#configuration} -`rs check` 没有独立的 `define.check()` 配置。它会使用 [`define.lint()`](../configuration#define-lint) 中的 lint 配置,以及 [`define.fmt()`](../configuration#define-fmt) 中的格式化配置。 +`rs check` 使用 [`define.lint()`](../configuration#define-lint) 中的 lint 配置,以及 [`define.fmt()`](../configuration#define-fmt) 中的格式化配置。