CLI: Add -w alias for --write option (#8833)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-07-27 10:10:01 +08:00
1 parent b7659f770b
commit 466d4638b4
7 files changed
+42 -4

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
#### Add `-w` alias for `--write` option ([#8833](https://github.com/prettier/prettier/pull/8833) by [@fisker](https://github.com/fisker))
```console
# Prettier stable
$ prettier index.js -w
[warn] Ignored unknown option -w. Did you mean -_?
"use strict";
module.exports = require("./src/index");
# Prettier master
$ prettier index.js -w
index.js 30ms
```
+1 -1
View File
@@ -172,7 +172,7 @@ Prettier CLI will ignore files located in `node_modules` directory. To opt-out f
## `--write`
This rewrites all processed files in place. This is comparable to the `eslint --fix` workflow.
This rewrites all processed files in place. This is comparable to the `eslint --fix` workflow. You can also use `-w` alias.
## `--loglevel`
+1
View File
@@ -203,6 +203,7 @@ const options = {
},
write: {
type: "boolean",
alias: "w",
category: coreOptions.CATEGORY_OUTPUT,
description: "Edit files in-place. (Beware!)",
},
@@ -63,7 +63,7 @@ Output options:
-c, --check Check if the given files are formatted, print a human-friendly summary
message and paths to unformatted files (see also --list-different).
-l, --list-different Print the names of files that are different from Prettier's formatting (see also --check).
--write Edit files in-place. (Beware!)
-w, --write Edit files in-place. (Beware!)
Format options:
@@ -222,7 +222,7 @@ Output options:
-c, --check Check if the given files are formatted, print a human-friendly summary
message and paths to unformatted files (see also --list-different).
-l, --list-different Print the names of files that are different from Prettier's formatting (see also --check).
--write Edit files in-place. (Beware!)
-w, --write Edit files in-place. (Beware!)
Format options:
@@ -634,7 +634,7 @@ exports[`show detailed usage with --help with-node-modules (write) 1`] = `Array
exports[`show detailed usage with --help write (stderr) 1`] = `""`;
exports[`show detailed usage with --help write (stdout) 1`] = `
"--write
"-w, --write
Edit files in-place. (Beware!)
"
@@ -35,3 +35,20 @@ Array [
},
]
`;
exports[`write file with -w + unformatted file (stderr) 1`] = `""`;
exports[`write file with -w + unformatted file (stdout) 1`] = `
"unformatted.js 0ms
"
`;
exports[`write file with -w + unformatted file (write) 1`] = `
Array [
Object {
"content": "var x = 1;
",
"filename": "unformatted.js",
},
]
`;
+6
View File
@@ -8,6 +8,12 @@ describe("write file with --write + unformatted file", () => {
});
});
describe("write file with -w + unformatted file", () => {
runPrettier("cli/write", ["-w", "unformatted.js"]).test({
status: 0,
});
});
describe("do not write file with --write + formatted file", () => {
runPrettier("cli/write", ["--write", "formatted.js"]).test({
write: [],