Skip to content

Commit 92d215f

Browse files
committed
feat(fmt): add -l alias for list different
1 parent 616a9ce commit 92d215f

6 files changed

Lines changed: 24 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Format files with Prettier.
3131
${color.cyan('Options')}:
3232
-w, --write Write formatted files in place (default)
3333
--check Check whether files are formatted
34-
--list-different Print paths of unformatted files
34+
-l, --list-different Print paths of unformatted files
3535
--ignore-path <path> Path to an additional ignore file (repeatable)
3636
-u, --ignore-unknown Ignore unknown files
3737
--no-error-on-unmatched-pattern Do not error when no files match
@@ -59,7 +59,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
5959
options: {
6060
write: { type: 'boolean', short: 'w' },
6161
check: { type: 'boolean' },
62-
'list-different': { type: 'boolean' },
62+
'list-different': { type: 'boolean', short: 'l' },
6363
'ignore-path': { type: 'string', multiple: true },
6464
'ignore-unknown': { type: 'boolean', short: 'u' },
6565
'no-error-on-unmatched-pattern': { type: 'boolean' },

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ test('checks formatting without writing files', () => {
337337
expect(formattedResult.stderr).toBe('');
338338
});
339339

340-
test('lists only paths that differ', () => {
340+
test.each(['-l', '--list-different'])('lists only paths that differ with %s', (option) => {
341341
const source = 'const message="hello"';
342342
writeProjectFile('src/index.ts', source);
343343
writeProjectFile('src/formatted.ts', 'const formatted = true;\n');
344344

345-
const result = runFmt(['--list-different', 'src/*.ts']);
345+
const result = runFmt([option, 'src/*.ts']);
346346

347347
expect(result.status).toBe(1);
348348
expect(result.stdout).toBe('src/index.ts\n');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Format files with Prettier.
99
Options:
1010
-w, --write Write formatted files in place (default)
1111
--check Check whether files are formatted
12-
--list-different Print paths of unformatted files
12+
-l, --list-different Print paths of unformatted files
1313
--ignore-path <path> Path to an additional ignore file (repeatable)
1414
-u, --ignore-unknown Ignore unknown files
1515
--no-error-on-unmatched-pattern Do not error when no files match

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test.each([
3434
['-w', 'write'],
3535
['--write', 'write'],
3636
['--check', 'check'],
37+
['-l', 'list-different'],
3738
['--list-different', 'list-different'],
3839
] as const)('parses %s mode', (option, mode) => {
3940
expect(parseFmtCLIArgs([option])).toEqual({

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ rs format
3636
Check whether files are formatted without changing them. The output lists files with formatting issues and includes a human-friendly summary, making this option useful in CI:
3737

3838
```bash
39-
rs fmt . --check
39+
rs fmt --check
4040
```
4141

4242
`--check` cannot be combined with `--write` or `--list-different`.
@@ -110,7 +110,13 @@ When used with `--stdin-filepath`, unsupported input is skipped without writing
110110
Print the paths of unformatted files without the summary produced by `--check`. This is useful when another command needs to consume the output:
111111

112112
```bash
113-
rs fmt . --list-different
113+
rs fmt --list-different
114+
```
115+
116+
The short option `-l` is an alias for `--list-different`:
117+
118+
```bash
119+
rs fmt -l
114120
```
115121

116122
The option uses the same exit codes as `--check` and cannot be combined with `--write` or `--check`.
@@ -132,7 +138,7 @@ For example, a pre-commit script may always run `rs fmt`, even when the staged c
132138
Set the maximum number of formatting workers to a positive integer:
133139

134140
```bash
135-
rs fmt . --parallel-workers 4
141+
rs fmt --parallel-workers 4
136142
```
137143

138144
When this option is omitted, `rs fmt` automatically chooses up to eight workers based on the available CPU parallelism and the number of matched files. Set a lower value to limit CPU or memory usage in constrained environments.

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ rs format
3636
检查文件是否已格式化,但不修改文件。输出会列出存在格式问题的文件,并提供便于阅读的汇总信息,因此适合在 CI 中使用:
3737

3838
```bash
39-
rs fmt . --check
39+
rs fmt --check
4040
```
4141

4242
`--check` 不能与 `--write` 或 `--list-different` 同时使用。
@@ -110,7 +110,13 @@ rs fmt -u
110110
输出未格式化文件的路径,但不提供 `--check` 的汇总信息。需要将结果交给其他命令处理时,可以使用此选项:
111111

112112
```bash
113-
rs fmt . --list-different
113+
rs fmt --list-different
114+
```
115+
116+
短选项 `-l` 是 `--list-different` 的别名:
117+
118+
```bash
119+
rs fmt -l
114120
```
115121

116122
此选项与 `--check` 使用相同的退出状态码,且不能与 `--write` 或 `--check` 同时使用。
@@ -132,7 +138,7 @@ rs fmt --no-error-on-unmatched-pattern 'src/**/*.ts'
132138
将格式化 worker 的最大数量设置为正整数:
133139

134140
```bash
135-
rs fmt . --parallel-workers 4
141+
rs fmt --parallel-workers 4
136142
```
137143

138144
省略此选项时,`rs fmt` 会根据可用的 CPU 并行度和匹配的文件数量,自动选择最多 8 个 worker。在资源受限的环境中,可以设置较小的值来限制 CPU 或内存用量。

0 commit comments

Comments
 (0)