Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/rstack/src/fmt/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ${color.yellow(' $ rs fmt [options] [files/globs...]')}
Format files with Prettier.

${color.cyan('Options')}:
--write Write formatted files in place (default)
-w, --write Write formatted files in place (default)
--check Check whether files are formatted
--list-different Print paths of unformatted files
--ignore-path <path> Path to an additional ignore file (repeatable)
Expand Down Expand Up @@ -57,7 +57,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
const { values, positionals } = parseArgs({
args,
options: {
write: { type: 'boolean' },
write: { type: 'boolean', short: 'w' },
check: { type: 'boolean' },
'list-different': { type: 'boolean' },
'ignore-path': { type: 'string', multiple: true },
Expand Down
11 changes: 11 additions & 0 deletions packages/rstack/tests/cli/fmt/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ test('formats the current directory with Prettier defaults', () => {
expect(readProjectFile('index.ts')).toBe('const message = "hello";\n');
});

test('accepts -w as an alias for --write', () => {
writeProjectFile('index.ts', 'const message="hello"');

const result = runFmt(['-w', 'index.ts']);

expect(result.status).toBe(0);
expectWriteSummary(result.stdout, 1, 1);
expect(result.stderr).toBe('');
expect(readProjectFile('index.ts')).toBe('const message = "hello";\n');
});

test('formats files in node_modules with --with-node-modules', () => {
const source = 'const message="hello"';
writeProjectFile('node_modules/example/index.ts', source);
Expand Down
2 changes: 1 addition & 1 deletion packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`provides command help 1`] = `
Format files with Prettier.

Options:
--write Write formatted files in place (default)
-w, --write Write formatted files in place (default)
--check Check whether files are formatted
--list-different Print paths of unformatted files
--ignore-path <path> Path to an additional ignore file (repeatable)
Expand Down
1 change: 1 addition & 0 deletions packages/rstack/tests/fmt/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('uses write mode by default', () => {
});

test.each([
['-w', 'write'],
['--write', 'write'],
['--check', 'check'],
['--list-different', 'list-different'],
Expand Down
6 changes: 6 additions & 0 deletions website/docs/en/guide/cli/fmt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@ Write formatted files in place. This is the default mode, so specifying `--write
rs fmt src --write
```

The short option `-w` is an alias for `--write`:

```bash
rs fmt -w src
```

`--write` cannot be combined with `--check` or `--list-different`.
6 changes: 6 additions & 0 deletions website/docs/zh/guide/cli/fmt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@ rs fmt --with-node-modules node_modules/example/index.js
rs fmt src --write
```

短选项 `-w` 是 `--write` 的别名:

```bash
rs fmt -w src
```

`--write` 不能与 `--check` 或 `--list-different` 同时使用。