From c26301a408e4a7032ab75b4e77490fb9076008ab Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 5 Aug 2026 18:49:15 +0800 Subject: [PATCH] feat(fmt): add -w alias for write --- packages/rstack/src/fmt/cli.ts | 4 ++-- packages/rstack/tests/cli/fmt/index.test.ts | 11 +++++++++++ .../rstack/tests/fmt/__snapshots__/cli.test.ts.snap | 2 +- packages/rstack/tests/fmt/cli.test.ts | 1 + website/docs/en/guide/cli/fmt.mdx | 6 ++++++ website/docs/zh/guide/cli/fmt.mdx | 6 ++++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/rstack/src/fmt/cli.ts b/packages/rstack/src/fmt/cli.ts index 7cada94..3c06ec1 100644 --- a/packages/rstack/src/fmt/cli.ts +++ b/packages/rstack/src/fmt/cli.ts @@ -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 to an additional ignore file (repeatable) @@ -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 }, diff --git a/packages/rstack/tests/cli/fmt/index.test.ts b/packages/rstack/tests/cli/fmt/index.test.ts index cdd41b7..30042a0 100644 --- a/packages/rstack/tests/cli/fmt/index.test.ts +++ b/packages/rstack/tests/cli/fmt/index.test.ts @@ -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); diff --git a/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap b/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap index 9d69d08..c6b1a7d 100644 --- a/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap +++ b/packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap @@ -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 to an additional ignore file (repeatable) diff --git a/packages/rstack/tests/fmt/cli.test.ts b/packages/rstack/tests/fmt/cli.test.ts index e687031..19d5ae8 100644 --- a/packages/rstack/tests/fmt/cli.test.ts +++ b/packages/rstack/tests/fmt/cli.test.ts @@ -31,6 +31,7 @@ test('uses write mode by default', () => { }); test.each([ + ['-w', 'write'], ['--write', 'write'], ['--check', 'check'], ['--list-different', 'list-different'], diff --git a/website/docs/en/guide/cli/fmt.mdx b/website/docs/en/guide/cli/fmt.mdx index 9e4f09e..bb6edf4 100644 --- a/website/docs/en/guide/cli/fmt.mdx +++ b/website/docs/en/guide/cli/fmt.mdx @@ -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`. diff --git a/website/docs/zh/guide/cli/fmt.mdx b/website/docs/zh/guide/cli/fmt.mdx index a425863..afe8c57 100644 --- a/website/docs/zh/guide/cli/fmt.mdx +++ b/website/docs/zh/guide/cli/fmt.mdx @@ -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` 同时使用。