Skip to content

Commit 61afddf

Browse files
committed
feat(fmt): add -u alias for ignore unknown
1 parent 52dc7a4 commit 61afddf

6 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎packages/rstack/src/fmt/cli.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ${color.cyan('Options')}:
3232
--check Check whether files are formatted
3333
--list-different Print paths of unformatted files
3434
--ignore-path <path> Path to an additional ignore file (repeatable)
35-
--ignore-unknown Ignore unknown files
35+
-u, --ignore-unknown Ignore unknown files
3636
--no-error-on-unmatched-pattern Do not error when no files match
3737
--parallel-workers <count> Number of parallel workers
3838
--stdin-filepath <path> Format stdin as if it were saved at <path>
@@ -59,7 +59,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
5959
check: { type: 'boolean' },
6060
'list-different': { type: 'boolean' },
6161
'ignore-path': { type: 'string', multiple: true },
62-
'ignore-unknown': { type: 'boolean' },
62+
'ignore-unknown': { type: 'boolean', short: 'u' },
6363
'no-error-on-unmatched-pattern': { type: 'boolean' },
6464
'parallel-workers': { type: 'string' },
6565
'stdin-filepath': { type: 'string' },

‎packages/rstack/tests/cli/fmt/index.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ test('ignores unsupported files with --ignore-unknown', () => {
640640
writeProjectFile('notes.unknown', 'plain text');
641641

642642
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
643-
const result = runFmt([...modeArgs, '--ignoreUnknown', 'notes.unknown']);
643+
const result = runFmt([...modeArgs, '--ignore-unknown', 'notes.unknown']);
644644

645645
expect(result.status).toBe(0);
646646
expect(result.stdout).toBe(
@@ -652,6 +652,16 @@ test('ignores unsupported files with --ignore-unknown', () => {
652652
}
653653
});
654654

655+
test('supports -u as an alias for --ignore-unknown', () => {
656+
writeProjectFile('notes.unknown', 'plain text');
657+
658+
const result = runFmt(['-u', 'notes.unknown']);
659+
660+
expect(result.status).toBe(0);
661+
expect(result.stdout).toBe('');
662+
expect(result.stderr).toBe('');
663+
});
664+
655665
test('does not treat unmatched patterns as unknown files', () => {
656666
const result = runFmt(['--ignore-unknown', 'missing/**/*.unknown']);
657667

‎packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Options:
1111
--check Check whether files are formatted
1212
--list-different Print paths of unformatted files
1313
--ignore-path <path> Path to an additional ignore file (repeatable)
14-
--ignore-unknown Ignore unknown files
14+
-u, --ignore-unknown Ignore unknown files
1515
--no-error-on-unmatched-pattern Do not error when no files match
1616
--parallel-workers <count> Number of parallel workers
1717
--stdin-filepath <path> Format stdin as if it were saved at <path>

‎packages/rstack/tests/fmt/cli.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ test('parses --no-error-on-unmatched-pattern', () => {
107107
expect(parseFmtCLIArgs(['--no-error-on-unmatched-pattern']).noErrorOnUnmatchedPattern).toBe(true);
108108
});
109109

110-
test.each(['--ignore-unknown', '--ignoreUnknown'])('parses %s', (option) => {
110+
test.each(['-u', '--ignore-unknown', '--ignoreUnknown'])('parses %s', (option) => {
111111
expect(parseFmtCLIArgs([option]).ignoreUnknown).toBe(true);
112112
});
113113

‎website/docs/en/guide/cli/fmt.mdx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ Each file acts as a separate ignore source. See [Ignore order](../formatting#ign
9292
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:
9393

9494
```bash
95-
rs fmt --ignore-unknown '**/*'
95+
rs fmt --ignore-unknown
96+
```
97+
98+
The short option `-u` is an alias for `--ignore-unknown`.
99+
100+
```bash
101+
rs fmt -u
96102
```
97103

98104
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.

‎website/docs/zh/guide/cli/fmt.mdx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ rs fmt --ignore-path .prettierignore --ignore-path config/format.ignore
9292
忽略无法推断 parser 的匹配文件。即使所有匹配文件的类型均未知,该选项也可以让命令成功退出:
9393

9494
```bash
95-
rs fmt --ignore-unknown '**/*'
95+
rs fmt --ignore-unknown
96+
```
97+
98+
短选项 `-u` 是 `--ignore-unknown` 的别名。
99+
100+
```bash
101+
rs fmt -u
96102
```
97103

98104
此选项不会忽略未匹配路径或 glob 的错误。如果集成需要同时容忍这两种情况,可以将它与 [`--no-error-on-unmatched-pattern`](#--no-error-on-unmatched-pattern) 一起使用。

0 commit comments

Comments
 (0)