You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 331e15c
Browse filesBrowse the repository at this point in the historyBrowse files
The `rs fmt` command is built on [Prettier](https://prettier.io/). It processes files in parallel by default and uses the high-performance [Yuku](https://yuku.fyi/) parser for JavaScript and TypeScript, providing better performance than using Prettier directly.
4
+
5
+
## Usage
6
+
7
+
```bash
8
+
rs fmt [options] [files/globs...]
9
+
```
10
+
11
+
Pass files, directories, or glob patterns to select what to format. When no inputs are provided, `rs fmt` formats the current directory. `rs format` is an alias for `rs fmt`.
|`--write`| Write formatted files in place. This is the default mode. |
18
+
|`--check`| Check formatting without writing files. Exits with code 1 when files are different. |
19
+
|`--list-different`| Print only unformatted paths. Exits with code 1 when files are different. |
20
+
|`--parallel-workers <count>`| Set the maximum number of formatting workers. |
21
+
|`-h, --help`| Display usage and option information. |
22
+
23
+
`--write`, `--check`, and `--list-different` are mutually exclusive.
24
+
25
+
Examples:
26
+
27
+
```bash
28
+
# Format the current directory in place
29
+
rs fmt
30
+
31
+
# Format specific files and directories
32
+
rs fmt src package.json
33
+
34
+
# Include and exclude files with quoted globs
35
+
rs fmt "src/**/*.{js,ts}""!src/generated/**"
36
+
37
+
# Check formatting in CI
38
+
rs fmt --check
39
+
```
40
+
41
+
## File discovery
42
+
43
+
Directory and glob discovery follows `.gitignore` files, skips binary files, and does not traverse version-control directories or `node_modules`. Files for which Prettier cannot infer a parser are skipped.
44
+
45
+
Use [`ignorePatterns`](../configuration#define-fmt) for additional project-specific exclusions. Both positive and negative input globs are resolved from the current working directory.
46
+
47
+
## Configuration
48
+
49
+
Configure formatting through [`define.fmt()`](../configuration#define-fmt) in the [Rstack configuration file](/guide/configuration#configuration-file):
50
+
51
+
```ts title="rstack.config.ts"
52
+
import { define } from'rstack';
53
+
54
+
define.fmt({
55
+
printWidth: 100,
56
+
singleQuote: true,
57
+
sortPackageJson: true,
58
+
ignorePatterns: ['dist/**'],
59
+
overrides: [
60
+
{
61
+
files: '*.md',
62
+
options: {
63
+
proseWrap: 'always',
64
+
},
65
+
},
66
+
],
67
+
});
68
+
```
69
+
70
+
`define.fmt()` accepts standard [Prettier options](https://prettier.io/docs/options) and the `overrides` field, plus these Rstack options:
71
+
72
+
-`ignorePatterns`: Gitignore-compatible patterns relative to the directory containing `rstack.config.ts`.
73
+
-`sortPackageJson`: Sort `package.json` fields before formatting. The default value is `false`.
74
+
75
+
:::warning Configuration sources
76
+
77
+
`rs fmt` does not load Prettier configuration files, `.prettierignore`, or `.editorconfig`. Move those settings and ignore rules into `define.fmt()`.
78
+
79
+
:::
80
+
81
+
When using [Prettier plugins](https://prettier.io/docs/plugins), pass each plugin as a package name, file path, or URL. Imported plugin objects are not supported because formatting runs in workers. Package names and relative paths are resolved from the Rstack configuration directory.
Copy file name to clipboardExpand all lines: website/docs/en/guide/configuration.mdx
+36-1Lines changed: 36 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,10 @@ define.test({
21
21
define.lint({
22
22
// Rslint configuration
23
23
});
24
+
25
+
define.fmt({
26
+
// Formatting configuration
27
+
});
24
28
```
25
29
26
30
The configuration file does not require a default export. Each `define.*()` API can be called at most once; defining the same configuration type more than once throws an error.
@@ -67,6 +71,7 @@ Configuration options follow the formats of the underlying tools. When using API
Defines the formatting configuration used by [`rs fmt`](./cli/fmt). Pass the configuration directly, or return it from a synchronous or asynchronous function.
172
+
173
+
`define.fmt()` accepts standard [Prettier options](https://prettier.io/docs/options) and the `overrides` field. It also supports `ignorePatterns` for Gitignore-compatible exclusions and `sortPackageJson` for sorting `package.json` fields before formatting.
174
+
175
+
```ts title="rstack.config.ts"
176
+
import { define } from'rstack';
177
+
178
+
define.fmt({
179
+
printWidth: 100,
180
+
singleQuote: true,
181
+
sortPackageJson: true,
182
+
ignorePatterns: ['dist/**'],
183
+
overrides: [
184
+
{
185
+
files: '*.md',
186
+
options: {
187
+
proseWrap: 'always',
188
+
},
189
+
},
190
+
],
191
+
});
192
+
```
193
+
194
+
Ignore patterns, override patterns, and relative plugin paths are resolved from the directory containing the Rstack configuration file. Specify Prettier plugins as package names, paths, or URLs rather than imported plugin objects.
195
+
196
+
`rs fmt` does not load Prettier configuration files, `.prettierignore`, or `.editorconfig`; keep all formatting options and ignore rules in `define.fmt()`.
197
+
164
198
### `define.staged()`\{#define-staged}
165
199
166
200
Defines the [lint-staged configuration](https://github.com/lint-staged/lint-staged#configuration) used to run tasks on staged Git files. It accepts either an object that maps glob patterns to tasks or a task-generator function. Tasks can be commands, command arrays, or functions supported by lint-staged.
@@ -169,7 +203,8 @@ Defines the [lint-staged configuration](https://github.com/lint-staged/lint-stag
0 commit comments