From 61afddf7ddc3be2eb329600c1c3308516e04699c Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 5 Aug 2026 16:29:15 +0800 Subject: [PATCH] feat(fmt): add -u alias for ignore unknown --- packages/rstack/src/fmt/cli.ts | 4 ++-- packages/rstack/tests/cli/fmt/index.test.ts | 12 +++++++++++- .../rstack/tests/fmt/__snapshots__/cli.test.ts.snap | 2 +- packages/rstack/tests/fmt/cli.test.ts | 2 +- website/docs/en/guide/cli/fmt.mdx | 8 +++++++- website/docs/zh/guide/cli/fmt.mdx | 8 +++++++- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/rstack/src/fmt/cli.ts b/packages/rstack/src/fmt/cli.ts index cff04bb..0dc1347 100644 --- a/packages/rstack/src/fmt/cli.ts +++ b/packages/rstack/src/fmt/cli.ts @@ -32,7 +32,7 @@ ${color.cyan('Options')}: --check Check whether files are formatted --list-different Print paths of unformatted files --ignore-path Path to an additional ignore file (repeatable) - --ignore-unknown Ignore unknown files + -u, --ignore-unknown Ignore unknown files --no-error-on-unmatched-pattern Do not error when no files match --parallel-workers Number of parallel workers --stdin-filepath Format stdin as if it were saved at @@ -59,7 +59,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => { check: { type: 'boolean' }, 'list-different': { type: 'boolean' }, 'ignore-path': { type: 'string', multiple: true }, - 'ignore-unknown': { type: 'boolean' }, + 'ignore-unknown': { type: 'boolean', short: 'u' }, 'no-error-on-unmatched-pattern': { type: 'boolean' }, 'parallel-workers': { type: 'string' }, 'stdin-filepath': { type: 'string' }, diff --git a/packages/rstack/tests/cli/fmt/index.test.ts b/packages/rstack/tests/cli/fmt/index.test.ts index 33ba3ca..7f568af 100644 --- a/packages/rstack/tests/cli/fmt/index.test.ts +++ b/packages/rstack/tests/cli/fmt/index.test.ts @@ -640,7 +640,7 @@ test('ignores unsupported files with --ignore-unknown', () => { writeProjectFile('notes.unknown', 'plain text'); for (const modeArgs of [[], ['--check'], ['--list-different']]) { - const result = runFmt([...modeArgs, '--ignoreUnknown', 'notes.unknown']); + const result = runFmt([...modeArgs, '--ignore-unknown', 'notes.unknown']); expect(result.status).toBe(0); expect(result.stdout).toBe( @@ -652,6 +652,16 @@ test('ignores unsupported files with --ignore-unknown', () => { } }); +test('supports -u as an alias for --ignore-unknown', () => { + writeProjectFile('notes.unknown', 'plain text'); + + const result = runFmt(['-u', 'notes.unknown']); + + expect(result.status).toBe(0); + expect(result.stdout).toBe(''); + expect(result.stderr).toBe(''); +}); + test('does not treat unmatched patterns as unknown files', () => { const result = runFmt(['--ignore-unknown', 'missing/**/*.unknown']); diff --git a/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap b/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap index 62ae169..2df10bd 100644 --- a/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap +++ b/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap @@ -11,7 +11,7 @@ Options: --check Check whether files are formatted --list-different Print paths of unformatted files --ignore-path Path to an additional ignore file (repeatable) - --ignore-unknown Ignore unknown files + -u, --ignore-unknown Ignore unknown files --no-error-on-unmatched-pattern Do not error when no files match --parallel-workers Number of parallel workers --stdin-filepath Format stdin as if it were saved at diff --git a/packages/rstack/tests/fmt/cli.test.ts b/packages/rstack/tests/fmt/cli.test.ts index cf5e190..9521ccb 100644 --- a/packages/rstack/tests/fmt/cli.test.ts +++ b/packages/rstack/tests/fmt/cli.test.ts @@ -107,7 +107,7 @@ test('parses --no-error-on-unmatched-pattern', () => { expect(parseFmtCLIArgs(['--no-error-on-unmatched-pattern']).noErrorOnUnmatchedPattern).toBe(true); }); -test.each(['--ignore-unknown', '--ignoreUnknown'])('parses %s', (option) => { +test.each(['-u', '--ignore-unknown', '--ignoreUnknown'])('parses %s', (option) => { expect(parseFmtCLIArgs([option]).ignoreUnknown).toBe(true); }); diff --git a/website/docs/en/guide/cli/fmt.mdx b/website/docs/en/guide/cli/fmt.mdx index 818140e..b92ac26 100644 --- a/website/docs/en/guide/cli/fmt.mdx +++ b/website/docs/en/guide/cli/fmt.mdx @@ -92,7 +92,13 @@ Each file acts as a separate ignore source. See [Ignore order](../formatting#ign Ignore matched files when no parser can be inferred. This allows the command to exit successfully even when every matched file has an unknown type: ```bash -rs fmt --ignore-unknown '**/*' +rs fmt --ignore-unknown +``` + +The short option `-u` is an alias for `--ignore-unknown`. + +```bash +rs fmt -u ``` This option does not suppress errors for unmatched paths or globs. Combine it with [`--no-error-on-unmatched-pattern`](#--no-error-on-unmatched-pattern) when an integration needs to tolerate both cases. diff --git a/website/docs/zh/guide/cli/fmt.mdx b/website/docs/zh/guide/cli/fmt.mdx index 3c810f3..78fd64f 100644 --- a/website/docs/zh/guide/cli/fmt.mdx +++ b/website/docs/zh/guide/cli/fmt.mdx @@ -92,7 +92,13 @@ rs fmt --ignore-path .prettierignore --ignore-path config/format.ignore 忽略无法推断 parser 的匹配文件。即使所有匹配文件的类型均未知,该选项也可以让命令成功退出: ```bash -rs fmt --ignore-unknown '**/*' +rs fmt --ignore-unknown +``` + +短选项 `-u` 是 `--ignore-unknown` 的别名。 + +```bash +rs fmt -u ``` 此选项不会忽略未匹配路径或 glob 的错误。如果集成需要同时容忍这两种情况,可以将它与 [`--no-error-on-unmatched-pattern`](#--no-error-on-unmatched-pattern) 一起使用。