From 284cdf4c3d02594bf5abd635b3b64a2d0ecb5acc Mon Sep 17 00:00:00 2001 From: Mark Avery Date: Tue, 25 Oct 2022 02:26:41 -0700 Subject: [PATCH] Style: updated failure message to be more formal (#11369) --- changelog_unreleased/cli/11369.md | 7 +++++++ docs/cli.md | 2 +- src/cli/format.js | 18 ++++++------------ .../__tests__/__snapshots__/check.js.snap | 6 +++--- .../__snapshots__/ignore-unknown.js.snap | 2 +- .../__snapshots__/infer-parser.js.snap | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 changelog_unreleased/cli/11369.md diff --git a/changelog_unreleased/cli/11369.md b/changelog_unreleased/cli/11369.md new file mode 100644 index 000000000..0986e5b46 --- /dev/null +++ b/changelog_unreleased/cli/11369.md @@ -0,0 +1,7 @@ +#### Updated failure message to be more informative (#11369 by @webark) + +Updated the "Forgot to run Prettier?" to "Run Prettier to fix." + +This keeps the same spirit of the message, but is less likely to be +misinterpreted as it's a more formal message rather than being +somewhat familial. diff --git a/docs/cli.md b/docs/cli.md index ca74d7827..cfeb493eb 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -69,7 +69,7 @@ Console output if some of the files require re-formatting: Checking formatting... [warn] src/fileA.js [warn] src/fileB.js -[warn] Code style issues found in 2 files. Forgot to run Prettier? +[warn] Code style issues found in 2 files. Run Prettier to fix. ``` The command will return exit code `1` in the second case, which is helpful inside the CI pipelines. diff --git a/src/cli/format.js b/src/cli/format.js index 1e36dea92..c90bce044 100644 --- a/src/cli/format.js +++ b/src/cli/format.js @@ -488,21 +488,15 @@ async function formatFiles(context) { if (context.argv.check) { if (numberOfUnformattedFilesFound === 0) { context.logger.log("All matched files use Prettier code style!"); - } else if (numberOfUnformattedFilesFound === 1) { - context.logger.warn( - context.argv.write - ? "Code style issues fixed in the above file." - : "Code style issues found in the above file. Forgot to run Prettier?" - ); } else { + const files = + numberOfUnformattedFilesFound === 1 + ? "the above file" + : `${numberOfUnformattedFilesFound} files`; context.logger.warn( context.argv.write - ? "Code style issues found in " + - numberOfUnformattedFilesFound + - " files." - : "Code style issues found in " + - numberOfUnformattedFilesFound + - " files. Forgot to run Prettier?" + ? `Code style issues fixed in ${files}.` + : `Code style issues found in ${files}. Run Prettier to fix.` ); } } diff --git a/tests/integration/__tests__/__snapshots__/check.js.snap b/tests/integration/__tests__/__snapshots__/check.js.snap index dff357f96..2acc6718f 100644 --- a/tests/integration/__tests__/__snapshots__/check.js.snap +++ b/tests/integration/__tests__/__snapshots__/check.js.snap @@ -3,7 +3,7 @@ exports[`--checks should print the number of files that need formatting (stderr) 1`] = ` "[warn] unformatted.js [warn] unformatted2.js -[warn] Code style issues found in 2 files. Forgot to run Prettier? +[warn] Code style issues found in 2 files. Run Prettier to fix. " `; @@ -16,13 +16,13 @@ exports[`--checks should print the number of files that need formatting (write) exports[`--checks works in CI just as in a non-TTY mode (stderr) 1`] = ` "[warn] unformatted.js -[warn] Code style issues found in the above file. Forgot to run Prettier? +[warn] Code style issues found in the above file. Run Prettier to fix. " `; exports[`--checks works in CI just as in a non-TTY mode (stderr) 2`] = ` "[warn] unformatted.js -[warn] Code style issues found in the above file. Forgot to run Prettier? +[warn] Code style issues found in the above file. Run Prettier to fix. " `; diff --git a/tests/integration/__tests__/__snapshots__/ignore-unknown.js.snap b/tests/integration/__tests__/__snapshots__/ignore-unknown.js.snap index 285b799cc..5ad4992f9 100644 --- a/tests/integration/__tests__/__snapshots__/ignore-unknown.js.snap +++ b/tests/integration/__tests__/__snapshots__/ignore-unknown.js.snap @@ -31,7 +31,7 @@ exports[`ignore-unknown alias (stdout) 1`] = ` exports[`ignore-unknown check (stderr) 1`] = ` "[warn] javascript.js -[warn] Code style issues found in the above file. Forgot to run Prettier? +[warn] Code style issues found in the above file. Run Prettier to fix. " `; diff --git a/tests/integration/__tests__/__snapshots__/infer-parser.js.snap b/tests/integration/__tests__/__snapshots__/infer-parser.js.snap index 9e75d1a6c..e8d0b3581 100644 --- a/tests/integration/__tests__/__snapshots__/infer-parser.js.snap +++ b/tests/integration/__tests__/__snapshots__/infer-parser.js.snap @@ -3,7 +3,7 @@ exports[`--check with unknown path and no parser multiple files (stderr) 1`] = ` "[error] No parser could be inferred for file: FOO [warn] foo.js -[warn] Code style issues found in the above file. Forgot to run Prettier? +[warn] Code style issues found in the above file. Run Prettier to fix. " `;