From 1f644019157c5009a5338c20fe8a3e1d1391c80e Mon Sep 17 00:00:00 2001 From: Georgii Dolzhykov Date: Thu, 27 Feb 2020 02:19:52 +0200 Subject: [PATCH] remove --stdin (#7668) --- changelog_unreleased/cli/pr-7668.md | 3 +++ docs/vim.md | 4 ++-- src/cli/constant.js | 4 ---- src/cli/index.js | 3 ++- .../__tests__/__snapshots__/early-exit.js.snap | 2 -- .../__snapshots__/help-options.js.snap | 11 ----------- tests_integration/__tests__/infer-parser.js | 18 ++++++++---------- .../__tests__/plugin-precedence.js | 2 +- tests_integration/__tests__/syntax-error.js | 2 +- .../__tests__/with-config-precedence.js | 9 +-------- 10 files changed, 18 insertions(+), 40 deletions(-) create mode 100644 changelog_unreleased/cli/pr-7668.md diff --git a/changelog_unreleased/cli/pr-7668.md b/changelog_unreleased/cli/pr-7668.md new file mode 100644 index 000000000..df86184ae --- /dev/null +++ b/changelog_unreleased/cli/pr-7668.md @@ -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. diff --git a/docs/vim.md b/docs/vim.md index 54d9b74f6..aff01ba8d 100644 --- a/docs/vim.md +++ b/docs/vim.md @@ -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 +nnoremap gp :silent %!prettier --stdin-filepath % --trailing-comma all --single-quote ``` 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. diff --git a/src/cli/constant.js b/src/cli/constant.js index 05f7047fe..0751baf2a 100644 --- a/src/cli/constant.js +++ b/src/cli/constant.js @@ -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." diff --git a/src/cli/index.js b/src/cli/index.js index 56f7ee6c4..2bcecf1c4 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -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); diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index ddc5ef0d2..bbe9c1472 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -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 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 to the file to pretend that stdin comes from. --support-info Print support information as JSON. -v, --version Print Prettier version. diff --git a/tests_integration/__tests__/__snapshots__/help-options.js.snap b/tests_integration/__tests__/__snapshots__/help-options.js.snap index 27c849c32..d249b98d2 100644 --- a/tests_integration/__tests__/__snapshots__/help-options.js.snap +++ b/tests_integration/__tests__/__snapshots__/help-options.js.snap @@ -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`] = ` diff --git a/tests_integration/__tests__/infer-parser.js b/tests_integration/__tests__/infer-parser.js index 3acaf440d..6854515c9 100644 --- a/tests_integration/__tests__/infer-parser.js +++ b/tests_integration/__tests__/infer-parser.js @@ -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, diff --git a/tests_integration/__tests__/plugin-precedence.js b/tests_integration/__tests__/plugin-precedence.js index 4c6104227..2a8935df2 100644 --- a/tests_integration/__tests__/plugin-precedence.js +++ b/tests_integration/__tests__/plugin-precedence.js @@ -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({ diff --git a/tests_integration/__tests__/syntax-error.js b/tests_integration/__tests__/syntax-error.js index 6413d5d69..969d74066 100644 --- a/tests_integration/__tests__/syntax-error.js +++ b/tests_integration/__tests__/syntax-error.js @@ -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 diff --git a/tests_integration/__tests__/with-config-precedence.js b/tests_integration/__tests__/with-config-precedence.js index 102e67416..5cf57023f 100644 --- a/tests_integration/__tests__/with-config-precedence.js +++ b/tests_integration/__tests__/with-config-precedence.js @@ -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()" } // 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"