Skip to content

Commit 6494ba2

Browse files
authored
docs: improve rs fmt CLI option reference (#171)
1 parent 0f20a80 commit 6494ba2

2 files changed

Lines changed: 128 additions & 22 deletions

File tree

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

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The `rs fmt` command formats files or checks whether they are formatted. For det
88
rs fmt [options] [files/globs...]
99
```
1010

11-
Pass files, directories, or glob patterns to choose what to format. When no paths are provided, `rs fmt` formats the current directory.
11+
Pass files, directories, or glob patterns to choose what to format. When no paths are provided, `rs fmt` formats the current directory. See [Formatting scope](../formatting#formatting-scope) for path resolution and ignore rules.
1212

1313
Examples:
1414

@@ -31,15 +31,68 @@ rs format
3131

3232
## Options
3333

34-
| Option | Description |
35-
| ---------------------------- | ----------------------------------------------------------------------------------- |
36-
| `--write` | Write formatted files in place. This is the default mode. |
37-
| `--check` | Check formatting without writing files. Exits with code 1 when files are different. |
38-
| `--list-different` | Print only unformatted paths. Exits with code 1 when files are different. |
39-
| `--parallel-workers <count>` | Set the maximum number of formatting workers. |
40-
| `--stdin-filepath <path>` | Format stdin as if it were saved at `<path>` and print the result to stdout. |
41-
| `-h, --help` | Display usage and option information. |
34+
### `--check`
4235

43-
> `--write`, `--check`, and `--list-different` are mutually exclusive.
36+
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:
4437

45-
> `--stdin-filepath` cannot be combined with `--write`, `--check`, `--list-different`, or file arguments.
38+
```bash
39+
rs fmt . --check
40+
```
41+
42+
`--check` cannot be combined with `--write` or `--list-different`.
43+
44+
The command uses the following exit codes:
45+
46+
| Code | Meaning |
47+
| ---- | --------------------------------------------------------- |
48+
| `0` | All matched files are formatted. |
49+
| `1` | One or more matched files have formatting issues. |
50+
| `2` | `rs fmt` could not run or encountered a formatting error. |
51+
52+
### `-h, --help`
53+
54+
Display usage and option information without formatting files:
55+
56+
```bash
57+
rs fmt --help
58+
```
59+
60+
### `--list-different`
61+
62+
Print the paths of unformatted files without the summary produced by `--check`. This is useful when another command needs to consume the output:
63+
64+
```bash
65+
rs fmt . --list-different
66+
```
67+
68+
The option uses the same exit codes as `--check` and cannot be combined with `--write` or `--check`.
69+
70+
### `--parallel-workers <count>`
71+
72+
Set the maximum number of formatting workers to a positive integer:
73+
74+
```bash
75+
rs fmt . --parallel-workers 4
76+
```
77+
78+
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.
79+
80+
### `--stdin-filepath <path>`
81+
82+
Format content received from stdin as if it were saved at `<path>`. The path determines the parser and matching configuration overrides, but it does not need to exist on disk. The formatted content is written to stdout:
83+
84+
```bash
85+
cat src/index.ts | rs fmt --stdin-filepath src/index.ts
86+
```
87+
88+
`--stdin-filepath` cannot be combined with file arguments or with `--write`, `--check`, or `--list-different`. See [Formatting stdin](../formatting#formatting-stdin) for details.
89+
90+
### `--write`
91+
92+
Write formatted files in place. This is the default mode, so specifying `--write` is optional:
93+
94+
```bash
95+
rs fmt src --write
96+
```
97+
98+
`--write` cannot be combined with `--check` or `--list-different`.

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

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
rs fmt [options] [files/globs...]
99
```
1010

11-
可以传入文件、目录或 glob 模式来指定格式化范围。不传入路径时,`rs fmt` 会格式化当前目录。
11+
可以传入文件、目录或 glob 模式来指定格式化范围。不传入路径时,`rs fmt` 会格式化当前目录。路径解析和忽略规则请参考[格式化范围](../formatting#formatting-scope)
1212

1313
示例:
1414

@@ -31,15 +31,68 @@ rs format
3131

3232
## 选项 \{#options}
3333

34-
| 选项 | 说明 |
35-
| ---------------------------- | --------------------------------------------------------- |
36-
| `--write` | 将格式化结果写回文件。这是默认模式。 |
37-
| `--check` | 检查格式但不写入文件;存在格式差异时以状态码 1 退出。 |
38-
| `--list-different` | 仅输出未格式化的路径;存在格式差异时以状态码 1 退出。 |
39-
| `--parallel-workers <count>` | 设置格式化 worker 的最大数量。 |
40-
| `--stdin-filepath <path>` | 将标准输入按保存在 `<path>` 的文件格式化并输出到 stdout。 |
41-
| `-h, --help` | 显示命令用法和选项。 |
34+
### `--check`
4235

43-
> `--write``--check``--list-different` 不能同时使用。
36+
检查文件是否已格式化,但不修改文件。输出会列出存在格式问题的文件,并提供便于阅读的汇总信息,因此适合在 CI 中使用:
4437

45-
> `--stdin-filepath` 不能与 `--write``--check``--list-different` 或文件参数同时使用。
38+
```bash
39+
rs fmt . --check
40+
```
41+
42+
`--check` 不能与 `--write``--list-different` 同时使用。
43+
44+
该命令使用以下退出状态码:
45+
46+
| 状态码 | 含义 |
47+
| ------ | ------------------------------------------- |
48+
| `0` | 所有匹配的文件均已格式化。 |
49+
| `1` | 一个或多个匹配的文件存在格式问题。 |
50+
| `2` | `rs fmt` 无法运行或在格式化过程中遇到错误。 |
51+
52+
### `-h, --help`
53+
54+
显示命令用法和选项信息,但不格式化文件:
55+
56+
```bash
57+
rs fmt --help
58+
```
59+
60+
### `--list-different`
61+
62+
输出未格式化文件的路径,但不提供 `--check` 的汇总信息。需要将结果交给其他命令处理时,可以使用此选项:
63+
64+
```bash
65+
rs fmt . --list-different
66+
```
67+
68+
此选项与 `--check` 使用相同的退出状态码,且不能与 `--write``--check` 同时使用。
69+
70+
### `--parallel-workers <count>`
71+
72+
将格式化 worker 的最大数量设置为正整数:
73+
74+
```bash
75+
rs fmt . --parallel-workers 4
76+
```
77+
78+
省略此选项时,`rs fmt` 会根据可用的 CPU 并行度和匹配的文件数量,自动选择最多 8 个 worker。在资源受限的环境中,可以设置较小的值来限制 CPU 或内存用量。
79+
80+
### `--stdin-filepath <path>`
81+
82+
将 stdin 传入的内容按保存在 `<path>` 的文件进行格式化。该路径用于确定 parser 和匹配的覆盖配置,但不需要在磁盘上真实存在。格式化结果会输出到 stdout:
83+
84+
```bash
85+
cat src/index.ts | rs fmt --stdin-filepath src/index.ts
86+
```
87+
88+
`--stdin-filepath` 不能与文件参数或 `--write``--check``--list-different` 同时使用。详细说明请参考[格式化标准输入](../formatting#formatting-stdin)
89+
90+
### `--write`
91+
92+
将格式化结果写回文件。这是默认模式,因此可以省略 `--write`
93+
94+
```bash
95+
rs fmt src --write
96+
```
97+
98+
`--write` 不能与 `--check``--list-different` 同时使用。

0 commit comments

Comments
 (0)