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
3 changes: 0 additions & 3 deletions packages/rstack/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ async function runCheckCLI(args: string[]): Promise<void> {
]);

const lintExitCode = Number(process.exitCode ?? 0);
if (values.fix && lintExitCode !== 0) {
return;
}

// Rslint loads its one-shot config through Node's module cache. Import the
// same URL to read the Rstack config exported for the following fmt phase.
Expand Down
36 changes: 31 additions & 5 deletions packages/rstack/tests/cli/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,42 @@ test('preserves a formatter error exit code after lint fails', () => {
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');
test('formats lint fixes even when unfixable errors remain', () => {
writeProjectFile(
'rstack.config.ts',
`import { define } from 'rstack';
define.lint([{
files: ['**/*.js'],
rules: { curly: 'error', 'no-debugger': 'error' },
}]);
`,
);
writeProjectFile('src/index.js', 'debugger;let value=true;if(value) value++');

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('Formatting...');
expect(readProjectFile('src/index.js')).toBe('debugger;const value=true');
expect(result.stdout).toContain('Formatting completed in');
expect(readProjectFile('src/index.js')).toBe(
'debugger;\nlet value = true;\nif (value) {\n value++;\n}\n',
);
});

test('formats files even when type checking fails in fix mode', () => {
writeLintConfig();
writeProjectFile(
'tsconfig.json',
'{ "compilerOptions": { "strict": true }, "include": ["src"] }',
);
writeProjectFile('src/index.ts', 'const value: string=1');

const result = runCheck(['--fix', '--type-check', 'src/index.ts']);

expect(result.status).toBe(1);
expect(`${result.stdout}\n${result.stderr}`).toContain('TS2322');
expect(result.stdout).toContain('Formatting completed in');
expect(readProjectFile('src/index.ts')).toBe('const value: string = 1;\n');
});
12 changes: 11 additions & 1 deletion packages/rstack/tests/config/reload-doc-config/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ define.doc({
root: 'docs',
title: '${title}',
builderConfig: {
// Avoid disk cache contention between dev server processes in this fixture.
performance: { buildCache: false },
dev: {
watchFiles: {
paths: ${JSON.stringify(userWatchFile)},
Expand Down Expand Up @@ -83,6 +85,9 @@ import { title } from './test-temp-imported.ts';
define.doc({
root: 'docs',
title,
builderConfig: {
performance: { buildCache: false },
},
});
`,
);
Expand Down Expand Up @@ -130,7 +135,12 @@ test('should restart doc dev server when an imported shared config changes', asy
import { sharedConfig } from './test-temp-shared.ts';

define.extends([sharedConfig]);
define.doc({ root: 'docs' });
define.doc({
root: 'docs',
builderConfig: {
performance: { buildCache: false },
},
});
`,
);

Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/guide/cli/check.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Automatically fix linting and formatting issues:
rs check --fix
```

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.
This first runs `rs lint --fix` to apply available lint fixes, then `rs fmt --write` to format the updated files. Formatting still runs if lint or type errors remain, and the command exits with a non-zero code if either step fails.

### `--type-check`

Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/cli/check.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rs check src/index.ts packages/utils
rs check --fix
```

该选项会先运行 `rs lint --fix`,自动修复 lint 问题。只有 lint 和已启用的类型检查都通过,才会继续运行 `rs fmt --write`,格式化修复后的文件。
该选项会先运行 `rs lint --fix` 自动修复 lint 问题,再运行 `rs fmt --write` 格式化修复后的文件。即使仍有 lint 或类型错误,也会继续格式化;任一步骤失败,命令都会以非零退出码结束。

### `--type-check`

Expand Down
Loading