Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Revert "fix(cli): preserve check file scope in fix hint"
This reverts commit b2a5d56.
  • Loading branch information
chenjiahan committed Sep 2, 2026
commit 380cbe528b26ec74020b711e62bc10e29b5ff864
12 changes: 1 addition & 11 deletions packages/rstack/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ async function runRspressCLI(args: string[]): Promise<void> {

const RSLINT_CONFIG_PATH = join(import.meta.dirname, 'rslintConfig.js');

const SHELL_SAFE_ARGUMENT_REGEXP = /^[\w@%+=:,./-]+$/u;

const quoteShellArgument = (argument: string): string =>
SHELL_SAFE_ARGUMENT_REGEXP.test(argument)
? argument
: `'${argument.replaceAll("'", "'\"'\"'")}'`;

const formatCommand = (args: readonly string[]): string =>
args.map(quoteShellArgument).join(' ');

async function runRslintCLI(args: string[]): Promise<void> {
if (hasHelpFlag(args)) {
return printCommandHelp('lint');
Expand Down Expand Up @@ -202,7 +192,7 @@ async function runCheckCLI(args: string[]): Promise<void> {
'../fmt/cli.ts'
);
await runFmtCLI(['--check', ...fileArgs], {
fixCommand: formatCommand(['rs', 'fmt', ...fileArgs]),
fixCommand: 'rs fmt',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve selected paths in the formatter fix hint

When rs check <files...> finds a formatting issue, this hard-coded hint tells the user to run unscoped rs fmt; following it formats every configured file, including files deliberately excluded from the check. Build the fix command from the same positional scope, preserving -- and safely quoting paths, so the suggested repair matches the newly scoped workflow.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b2a5d56. The formatter hint now preserves -- and the original file scope, with shell-safe quoting for paths. Tests cover spaces, single quotes, and option-like filenames.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this fix in 380cbe5. We plan to address the hint together with rs check --fix by telling users to rerun the same command with --fix, which preserves the original file scope without reconstructing shell arguments.

loadedConfig,
});
}
Expand Down
22 changes: 5 additions & 17 deletions packages/rstack/tests/cli/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,16 @@ test('passes file arguments to lint and the formatting check', () => {
expect(result.stderr).toBe('');
});

test('preserves file arguments in the formatting fix command', () => {
writeLintConfig();
writeProjectFile("src/selected file's.ts", 'const selected=true');

const result = runCheck(["src/selected file's.ts"]);

expect(result.status).toBe(1);
expect(result.stderr).toContain(
`Run rs fmt -- 'src/selected file'"'"'s.ts' to fix.`,
);
});

test('supports file arguments after the option terminator', () => {
writeLintConfig();
writeProjectFile('--selected.ts', 'const selected=true');
writeProjectFile('--selected.ts', 'const selected = true;\n');

const result = runCheck(['--', '--selected.ts']);

expect(result.status).toBe(1);
expect(result.stderr).toContain(
'Formatting issues found in 1 file. Run rs fmt -- --selected.ts to fix.',
);
expect(result.status).toBe(0);
expect(result.stdout).toContain('Format check passed in');
expect(result.stdout).toContain('(1 file)');
expect(result.stderr).toBe('');
});

test('enables type checking only with --type-check', () => {
Expand Down