remove --stdin (#7668)

This commit is contained in:
Georgii Dolzhykov authored and GitHub committed 2020-02-27 02:19:52 +02:00
1 parent d469140322
commit 1f64401915
10 files changed
+18 -40

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
#### Remove `--stdin` ([#7668](https://github.com/prettier/prettier/pull/7668) by [@thorn0](https://github.com/thorn0))
This CLI flag, never properly documented, was supposed to make Prettier CLI read input from stdin, but Prettier CLI does so anyway when not given any file paths or glob patterns. So the flag was redundant. Now that it's been removed, if you use this flag in your commands, you'll see a warning: "Ignored unknown option". This warning is just information. It doesn't prevent the command from doing what it should do and doesn't affect the exit code.
+2 -2
View File
@@ -41,7 +41,7 @@ See `:help autocmd-events` in Vim for details.
It's recommended to use a [config file](configuration.md), but you can also add options in your `.vimrc`:
```
autocmd FileType javascript setlocal formatprg=prettier\ --stdin\ --single-quote\ --trailing-comma\ es5
autocmd FileType javascript setlocal formatprg=prettier\ --single-quote\ --trailing-comma\ es5
" Use formatprg when available
let g:neoformat_try_formatprg = 1
```
@@ -125,7 +125,7 @@ Update your `coc-settings.json` for languages that you want format on save.
If you want something really bare-bones, you can create a custom key binding. In this example, `gp` (mnemonic: "get pretty") is used to run prettier (with options) in the currently active buffer:
```
nnoremap gp :silent %!prettier --stdin --stdin-filepath % --trailing-comma all --single-quote<CR>
nnoremap gp :silent %!prettier --stdin-filepath % --trailing-comma all --single-quote<CR>
```
Note that if there's a syntax error in your code, the whole buffer will be replaced with an error message. You'll need to press `u` to get your code back.
-4
View File
@@ -187,10 +187,6 @@ const options = {
default: "log",
choices: ["silent", "error", "warn", "log", "debug"]
},
stdin: {
type: "boolean",
description: "Force reading input from stdin."
},
"support-info": {
type: "boolean",
description: "Print support information as JSON."
+2 -1
View File
@@ -57,7 +57,8 @@ function run(args) {
const hasFilePatterns = context.filePatterns.length !== 0;
const useStdin =
context.argv.stdin || (!hasFilePatterns && !process.stdin.isTTY);
!hasFilePatterns &&
(!process.stdin.isTTY || context.args["stdin-filepath"]);
if (context.argv["find-config-path"]) {
util.logResolvedConfigPathOrDie(context);
@@ -147,7 +147,6 @@ Other options:
--require-pragma Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
Defaults to false.
--stdin Force reading input from stdin.
--stdin-filepath <path> Path to the file to pretend that stdin comes from.
--support-info Print support information as JSON.
-v, --version Print Prettier version.
@@ -304,7 +303,6 @@ Other options:
--require-pragma Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
Defaults to false.
--stdin Force reading input from stdin.
--stdin-filepath <path> Path to the file to pretend that stdin comes from.
--support-info Print support information as JSON.
-v, --version Print Prettier version.
@@ -511,17 +511,6 @@ Default: false
exports[`show detailed usage with --help single-quote (write) 1`] = `Array []`;
exports[`show detailed usage with --help stdin (stderr) 1`] = `""`;
exports[`show detailed usage with --help stdin (stdout) 1`] = `
"--stdin
Force reading input from stdin.
"
`;
exports[`show detailed usage with --help stdin (write) 1`] = `Array []`;
exports[`show detailed usage with --help stdin-filepath (stderr) 1`] = `""`;
exports[`show detailed usage with --help stdin-filepath (stdout) 1`] = `
+8 -10
View File
@@ -5,7 +5,7 @@ const prettier = require("prettier/local");
describe("stdin no path and no parser", () => {
describe("logs error and exits with 2", () => {
runPrettier("cli/infer-parser/", ["--stdin"], { input: "foo" }).test({
runPrettier("cli/infer-parser/", [], { input: "foo" }).test({
status: 2,
stdout: "",
write: []
@@ -13,7 +13,7 @@ describe("stdin no path and no parser", () => {
});
describe("--check logs error but exits with 0", () => {
runPrettier("cli/infer-parser/", ["--check", "--stdin"], {
runPrettier("cli/infer-parser/", ["--check"], {
input: "foo"
}).test({
status: 0,
@@ -23,7 +23,7 @@ describe("stdin no path and no parser", () => {
});
describe("--list-different logs error but exits with 0", () => {
runPrettier("cli/infer-parser/", ["--list-different", "--stdin"], {
runPrettier("cli/infer-parser/", ["--list-different"], {
input: "foo"
}).test({
status: 0,
@@ -35,7 +35,7 @@ describe("stdin no path and no parser", () => {
describe("stdin with unknown path and no parser", () => {
describe("logs error and exits with 2", () => {
runPrettier("cli/infer-parser/", ["--stdin", "--stdin-filepath", "foo"], {
runPrettier("cli/infer-parser/", ["--stdin-filepath", "foo"], {
input: "foo"
}).test({
status: 2,
@@ -45,11 +45,9 @@ describe("stdin with unknown path and no parser", () => {
});
describe("--check logs error but exits with 0", () => {
runPrettier(
"cli/infer-parser/",
["--check", "--stdin", "--stdin-filepath", "foo"],
{ input: "foo" }
).test({
runPrettier("cli/infer-parser/", ["--check", "--stdin-filepath", "foo"], {
input: "foo"
}).test({
status: 0,
stdout: "",
write: []
@@ -59,7 +57,7 @@ describe("stdin with unknown path and no parser", () => {
describe("--list-different logs error but exits with 0", () => {
runPrettier(
"cli/infer-parser/",
["--list-different", "--stdin", "--stdin-filepath", "foo"],
["--list-different", "--stdin-filepath", "foo"],
{ input: "foo" }
).test({
status: 0,
@@ -3,7 +3,7 @@
const runPrettier = require("../runPrettier");
describe("json-stringify takes precedence over json for package.json", () => {
runPrettier("plugins", ["--stdin", "--stdin-filepath=package.json"], {
runPrettier("plugins", ["--stdin-filepath=package.json"], {
input:
'{ "a": "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong" }'
}).test({
+1 -1
View File
@@ -3,7 +3,7 @@
const runPrettier = require("../runPrettier");
describe("exits with non-zero code when input has a syntax error", () => {
runPrettier("cli/with-shebang", ["--stdin", "--parser", "babel"], {
runPrettier("cli/with-shebang", ["--parser", "babel"], {
input: "a.2"
}).test({
status: 2
@@ -118,12 +118,7 @@ describe("CLI validate options with --config-precedence prefer-file", () => {
describe("CLI --stdin-filepath works with --config-precedence prefer-file", () => {
runPrettier(
"cli/config/",
[
"--stdin",
"--stdin-filepath=abc.ts",
"--no-semi",
"--config-precedence=prefer-file"
],
["--stdin-filepath=abc.ts", "--no-semi", "--config-precedence=prefer-file"],
{ input: "let x: keyof Y = foo<typeof X>()" } // typescript
).test({
stderr: "",
@@ -135,7 +130,6 @@ describe("CLI --stdin-filepath works with --config-precedence file-override", ()
runPrettier(
"cli/config/",
[
"--stdin",
"--stdin-filepath=abc.ts",
"--no-semi",
"--config-precedence=file-override"
@@ -151,7 +145,6 @@ describe("CLI --stdin-filepath works with --config-precedence cli-override", ()
runPrettier(
"cli/config/",
[
"--stdin",
"--stdin-filepath=abc.ts",
"--no-semi",
"--config-precedence=cli-override"