From 0eeed5ff9b129fc94eb1c04d1fb26c5868a714c7 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 22 Apr 2025 23:13:47 +0800 Subject: [PATCH 1/2] Synchronize snapshot with upstream --- .../__snapshots__/arg-parsing.js.snap | 127 +++-- test/__tests__/__snapshots__/check.js.snap | 54 +- .../__snapshots__/cursor-offset.js.snap | 23 +- .../__snapshots__/early-exit.js.snap | 521 ++++++++++++------ .../error-on-unmatched-pattern.js.snap | 52 +- .../ignore-absolute-path.js.snap | 12 +- .../__snapshots__/ignore-emoji.js.snap | 24 +- .../ignore-in-subdirectories.js.snap | 76 +-- .../ignore-relative-path.js.snap | 16 +- .../__snapshots__/ignore-unknown.js.snap | 105 ++-- .../__snapshots__/ignore-vcs-files.js.snap | 20 +- .../__snapshots__/invalid-ignore.js.snap | 12 +- .../__snapshots__/list-different.js.snap | 42 +- .../__snapshots__/patterns-glob.js.snap | 171 +++--- test/__tests__/__snapshots__/patterns.js.snap | 117 ++-- .../plugin-options-string.js.snap | 42 +- .../__snapshots__/plugin-options.js.snap | 86 ++- .../__snapshots__/print-code.js.snap | 17 +- .../__snapshots__/skip-folders.js.snap | 22 +- .../__snapshots__/syntax-error.js.snap | 14 +- .../__snapshots__/with-node-modules.js.snap | 65 ++- .../with-parser-inference.js.snap | 64 +-- .../__snapshots__/with-shebang.js.snap | 14 +- test/__tests__/__snapshots__/write.js.snap | 64 ++- test/utils.js | 45 +- 25 files changed, 1094 insertions(+), 711 deletions(-) diff --git a/test/__tests__/__snapshots__/arg-parsing.js.snap b/test/__tests__/__snapshots__/arg-parsing.js.snap index 3924dc8..58cb29f 100644 --- a/test/__tests__/__snapshots__/arg-parsing.js.snap +++ b/test/__tests__/__snapshots__/arg-parsing.js.snap @@ -1,69 +1,102 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`allow overriding flags (stderr) 1`] = `""`; - -exports[`allow overriding flags (write) 1`] = `[]`; - -exports[`boolean flags do not swallow the next argument (stderr) 1`] = `""`; - -exports[`boolean flags do not swallow the next argument (stdout) 1`] = `"console.log('could be single quote and without semi');"`; - -exports[`boolean flags do not swallow the next argument (write) 1`] = `[]`; +exports[`allow overriding flags 1`] = ` +{ + "stderr": "", + "write": [], +} +`; -exports[`negated options work (stderr) 1`] = `""`; +exports[`boolean flags do not swallow the next argument 1`] = ` +{ + "stderr": "", + "stdout": "console.log('could be single quote and without semi');", + "write": [], +} +`; -exports[`negated options work (stdout) 1`] = `"console.log("could be single quote and without semi")"`; +exports[`deprecated option values are warned 1`] = ` +{ + "stderr": "[warn] --jsx-bracket-same-line is deprecated.", + "stdout": "console.log("could be single quote and without semi");", + "write": [], +} +`; -exports[`negated options work (write) 1`] = `[]`; +exports[`negated options work 1`] = ` +{ + "stderr": "", + "stdout": "console.log("could be single quote and without semi")", + "write": [], +} +`; -exports[`number file/dir (stdout) 1`] = `"1/file-in-dir-named-1.js"`; +exports[`number file/dir 1`] = ` +{ + "stdout": "1/file-in-dir-named-1.js", +} +`; -exports[`number file/dir (stdout) 2`] = `"2.2/file-in-dir-named-2.2.js"`; +exports[`number file/dir 2`] = ` +{ + "stdout": "2.2/file-in-dir-named-2.2.js", +} +`; -exports[`number file/dir (stdout) 3`] = `"3"`; +exports[`number file/dir 3`] = ` +{ + "stdout": "3", +} +`; -exports[`number file/dir (stdout) 4`] = `"4.44"`; +exports[`number file/dir 4`] = ` +{ + "stdout": "4.44", +} +`; -exports[`number file/dir (stdout) 5`] = ` -"1/file-in-dir-named-1.js +exports[`number file/dir 5`] = ` +{ + "stdout": "1/file-in-dir-named-1.js 2.2/file-in-dir-named-2.2.js 3 -4.44" +4.44", +} `; -exports[`options with \`cliName\` should not allow to pass directly (stderr) 1`] = ` -"[warn] Ignored unknown option --filepath=file.js. -[error] No parser and no file path given, couldn't infer a parser." +exports[`options with \`cliName\` should not allow to pass directly 1`] = ` +{ + "stdout": "prettier();", +} `; -exports[`options with \`cliName\` should not allow to pass directly (stdout) 1`] = `"prettier();"`; - -exports[`options with \`cliName\` should not allow to pass directly (stdout) 2`] = `""`; - -exports[`unknown negated options are errored (stderr) 1`] = ` -" - Unknown option: "unknown" -" +exports[`options with \`cliName\` should not allow to pass directly 2`] = ` +{ + "stderr": "[warn] Ignored unknown option --filepath=file.js. +[error] No parser and no file path given, couldn't infer a parser.", + "stdout": "", +} `; -exports[`unknown negated options are errored (stdout) 1`] = `""`; - -exports[`unknown negated options are errored (write) 1`] = `[]`; - -exports[`unknown options are errored (stderr) 1`] = ` -" - Unknown option: "unknown" -" +exports[`unknown negated options are warned 1`] = ` +{ + "stderr": "[warn] Ignored unknown option --no-unknown.", + "stdout": "console.log("could be single quote and without semi");", + "write": [], +} `; -exports[`unknown options are errored (stdout) 1`] = `""`; - -exports[`unknown options are errored (write) 1`] = `[]`; - -exports[`unknown options may trigger a suggestion \`_\` (stderr) 1`] = ` -" - Unknown option: "a". Did you mean "v"? -" +exports[`unknown options are warned 1`] = ` +{ + "stderr": "[warn] Ignored unknown option --unknown.", + "stdout": "console.log("could be single quote and without semi");", + "write": [], +} `; -exports[`unknown options may trigger a suggestion \`_\` (stdout) 1`] = `""`; +exports[`unknown options not suggestion \`_\` 1`] = ` +{ + "stderr": "[warn] Ignored unknown option -a. Did you mean -c?", + "stdout": "console.log("could be single quote and without semi");", +} +`; diff --git a/test/__tests__/__snapshots__/check.js.snap b/test/__tests__/__snapshots__/check.js.snap index 4267983..39b0e8f 100644 --- a/test/__tests__/__snapshots__/check.js.snap +++ b/test/__tests__/__snapshots__/check.js.snap @@ -1,33 +1,41 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`--checks should print the number of files that need formatting (stderr) 1`] = ` -"[warn] unformatted.js +exports[`--checks should print the number of files that need formatting 1`] = ` +{ + "stderr": "[warn] unformatted.js [warn] unformatted2.js -[warn] Code style issues found in 2 files. Run Prettier with --write to fix." +[warn] Code style issues found in 2 files. Run Prettier with --write to fix.", + "stdout": "Checking formatting...", + "write": [], +} `; -exports[`--checks should print the number of files that need formatting (stdout) 1`] = `"Checking formatting..."`; - -exports[`--checks should print the number of files that need formatting (write) 1`] = `[]`; - -exports[`--checks works in CI just as in a non-TTY mode (stderr) 1`] = ` -"[warn] unformatted.js -[warn] Code style issues found in 1 file. Run Prettier with --write to fix." +exports[`--checks works in CI just as in a non-TTY mode 1`] = ` +{ + "stderr": "[warn] unformatted.js +[warn] Code style issues found in the above file. Run Prettier with --write to fix.", + "stdout": "Checking formatting...", + "write": [], +} `; -exports[`--checks works in CI just as in a non-TTY mode (stderr) 2`] = ` -"[warn] unformatted.js -[warn] Code style issues found in 1 file. Run Prettier with --write to fix." +exports[`--checks works in CI just as in a non-TTY mode 2`] = ` +{ + "stderr": "[warn] unformatted.js +[warn] Code style issues found in the above file. Run Prettier with --write to fix.", + "stdout": "Checking formatting...", + "write": [], +} `; -exports[`--checks works in CI just as in a non-TTY mode (stdout) 1`] = `"Checking formatting..."`; - -exports[`--checks works in CI just as in a non-TTY mode (stdout) 2`] = `"Checking formatting..."`; - -exports[`--checks works in CI just as in a non-TTY mode (write) 1`] = `[]`; - -exports[`--checks works in CI just as in a non-TTY mode (write) 2`] = `[]`; - -exports[`checks stdin with --check (write) 1`] = `[]`; +exports[`checks stdin with --check 1`] = ` +{ + "write": [], +} +`; -exports[`checks stdin with -c (alias for --check) (write) 1`] = `[]`; +exports[`checks stdin with -c (alias for --check) 1`] = ` +{ + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/cursor-offset.js.snap b/test/__tests__/__snapshots__/cursor-offset.js.snap index bdc1314..a0c2b2f 100644 --- a/test/__tests__/__snapshots__/cursor-offset.js.snap +++ b/test/__tests__/__snapshots__/cursor-offset.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`cursorOffset should not be affected by full-width character (stdout) 1`] = ` -"const x = [ +exports[`cursorOffset should not be affected by full-width character 1`] = ` +{ + "stdout": "const x = [ "中文", "中文", "中文", @@ -13,13 +14,15 @@ exports[`cursorOffset should not be affected by full-width character (stdout) 1` "中文", "中文", "中文", -];" +];", + "write": [], +} `; -exports[`cursorOffset should not be affected by full-width character (write) 1`] = `[]`; - -exports[`write cursorOffset to stderr with --cursor-offset (stderr) 1`] = `"1"`; - -exports[`write cursorOffset to stderr with --cursor-offset (stdout) 1`] = `"1;"`; - -exports[`write cursorOffset to stderr with --cursor-offset (write) 1`] = `[]`; +exports[`write cursorOffset to stderr with --cursor-offset 1`] = ` +{ + "stderr": "1", + "stdout": "1;", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/early-exit.js.snap b/test/__tests__/__snapshots__/early-exit.js.snap index 214fca3..d04a83b 100644 --- a/test/__tests__/__snapshots__/early-exit.js.snap +++ b/test/__tests__/__snapshots__/early-exit.js.snap @@ -1,211 +1,372 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`show usage with --help (stderr) 1`] = `""`; - -exports[`show usage with --help (stdout) 1`] = ` -" - prettier 3.3.3 - - USAGE - - prettier [file/dir/glob...] [options] - prettier "src/**/*.js" --check - prettier "src/**/*.js" -l --no-cache - prettier "src/**/*.js" --write --no-parallel - prettier ./path/to/target/file.js --cache-location ./path/to/cache/file.json - - ARGUMENTS - - [file/dir/glob...] Files, directories or globs to format - - OUTPUT OPTIONS - - --check, -c Check if the given files are formatted, print a human-friendly summary (see also --list-different) - --list-different, -l Print the names of files that are different from Prettier's formatting (see also --check) - --write, -w Edit files in-place (Beware!) - - FORMAT OPTIONS - - --arrow-parens - Include parentheses around a sole arrow function parameter - Defaults to "always" - --bracket-same-line Put ">" of opening tags on the last line instead of on a new line - Defaults to "false" - --no-bracket-spacing Do not print spaces between brackets - Defaults to "true" - --embedded-language-formatting - Control how Prettier formats quoted code embedded in the file - Defaults to "auto" - --end-of-line - Which end of line characters to apply - Defaults to "lf" - --experimental-operator-position - Where to print operators when binary expressions wrap lines - Defaults to "end" - --experimental-ternaries - Use curious ternaries, with the question mark after the condition - Defaults to "false" - --html-whitespace-sensitivity - How to handle whitespaces in HTML - Defaults to "css" - --jsx-single-quote Use single quotes in JSX - Defaults to "false" - --object-wrap - How to wrap object literals - Defaults to "preserve" - --parser - Which parser to use - --print-width The line length where Prettier will try wrap - Defaults to "80" - --prose-wrap - How to wrap prose - Defaults to "preserve" - --quote-props - Change when properties in objects are quoted - Defaults to "as-needed" - --no-semi Do not print semicolons, except at the beginning of lines which may need them - Defaults to "true" - --single-attribute-per-line - Enforce single attribute per line in HTML, Vue and JSX - Defaults to "false" - --single-quote Use single quotes instead of double quotes - Defaults to "false" - --tab-width Number of spaces per indentation level - Defaults to "2" - --trailing-comma - Print trailing commas wherever possible when multi-line - Defaults to "all" - --use-tabs Indent with tabs instead of spaces - Defaults to "false" - --vue-indent-script-and-style - Indent script and style tags in Vue files - Defaults to "false" - - CONFIG OPTIONS - - --no-config Do not look for a configuration file - --config-path Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js) - --config-precedence - Define in which order config files and CLI options should be evaluated. - Defaults to "cli-override" - --no-editorconfig Don't take .editorconfig into account when parsing configuration - --no-ignore Do not look for an ignore file - --ignore-path Path to a file with patterns describing files to ignore - Multiple values are accepted - Defaults to [.gitignore, .prettierignore] - --plugin Add a plugin - Multiple plugins are accepted - Defaults to [] - --with-node-modules Process files inside the "node_modules" directory - - EDITOR OPTIONS - - --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting - Defaults to "-1" - --range-end Format code ending at a given character offset (exclusive) - The range will extend forwards to the end of the selected statement - Defaults to "Infinity" - --range-start Format code starting at a given character offset - The range will extend backwards to the start of the first line containing the selected statement - Defaults to "0" - - OTHER OPTIONS - - --help Display help for the command - --version, -v Display the version number - --no-cache Do not use the built-in caching mechanism - --cache-location Path to the cache file - --no-color Do not colorize output messages - --no-error-on-unmatched-pattern - Prevent errors when pattern is unmatched - --ignore-unknown, -u Ignore unknown files - --insert-pragma Insert @format pragma into file's first docblock comment - Defaults to "false" - --log-level - What level of logs to report - Defaults to "log" - --no-parallel Process files in parallel - Defaults to "true" - --parallel-workers Number of parallel workers to use - Defaults to "0" - --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-filepath Path to the file to pretend that stdin comes from - " -`; +exports[`show detailed usage with --help l (alias) 1`] = ` +{ + "stderr": "", + "stdout": "-l, --list-different -exports[`show usage with --help (write) 1`] = `[]`; + Print the names of files that are different from Prettier's formatting (see also --check).", + "write": [], +} +`; -exports[`show version with --version (stderr) 1`] = `""`; +exports[`show detailed usage with plugin options (manual resolution) 1`] = ` +{ + "stderr": "", + "stdout": "--tab-width -exports[`show version with --version (write) 1`] = `[]`; + Number of spaces per indentation level. -exports[`throw error with --check + --list-different (stderr) 1`] = ` -" - Incompatible options: "check" and "list-different" cannot be used together -" +Default: 2 +Plugin defaults: +* ../plugins/automatic/node_modules/prettier-plugin-bar/index.js: 4", + "write": [], +} `; -exports[`throw error with --check + --list-different (stdout) 1`] = `""`; +exports[`show usage with --help 1`] = ` +{ + "stderr": "", + "stdout": "Usage: prettier [options] [file/dir/glob ...] -exports[`throw error with --check + --list-different (write) 1`] = `[]`; +By default, output is written to stdout. +Stdin is read if it is piped to Prettier and no files are given. -exports[`throw error with --check + --write (stderr) 1`] = ` -" - Incompatible options: "check" and "write" cannot be used together -" -`; +Output options: -exports[`throw error with --check + --write (stdout) 1`] = `""`; + -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). + -w, --write Edit files in-place. (Beware!) -exports[`throw error with --check + --write (write) 1`] = `[]`; +Format options: -exports[`throw error with --list-different + --write (stderr) 1`] = ` -" - Incompatible options: "list-different" and "write" cannot be used together -" -`; + --arrow-parens + Include parentheses around a sole arrow function parameter. + Defaults to always. + --bracket-same-line Put > of opening tags on the last line instead of on a new line. + Defaults to false. + --no-bracket-spacing Do not print spaces between brackets. + --embedded-language-formatting + Control how Prettier formats quoted code embedded in the file. + Defaults to auto. + --end-of-line + Which end of line characters to apply. + Defaults to lf. + --experimental-operator-position + Where to print operators when binary expressions wrap lines. + Defaults to end. + --no-experimental-ternaries + Default behavior of ternaries; keep question marks on the same line as the consequent. + --html-whitespace-sensitivity + How to handle whitespaces in HTML. + Defaults to css. + --jsx-single-quote Use single quotes in JSX. + Defaults to false. + --object-wrap + How to wrap object literals. + Defaults to preserve. + --parser + Which parser to use. + --print-width The line length where Prettier will try wrap. + Defaults to 80. + --prose-wrap + How to wrap prose. + Defaults to preserve. + --quote-props + Change when properties in objects are quoted. + Defaults to as-needed. + --no-semi Do not print semicolons, except at the beginning of lines which may need them. + --single-attribute-per-line + Enforce single attribute per line in HTML, Vue and JSX. + Defaults to false. + --single-quote Use single quotes instead of double quotes. + Defaults to false. + --tab-width Number of spaces per indentation level. + Defaults to 2. + --trailing-comma + Print trailing commas wherever possible when multi-line. + Defaults to all. + --use-tabs Indent with tabs instead of spaces. + Defaults to false. + --vue-indent-script-and-style + Indent script and style tags in Vue files. + Defaults to false. + +Config options: + + --config Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js). + --no-config Do not look for a configuration file. + --config-precedence + Define in which order config files and CLI options should be evaluated. + Defaults to cli-override. + --no-editorconfig Don't take .editorconfig into account when parsing configuration. + --find-config-path + Find and print the path to a configuration file for the given input file. + --ignore-path Path to a file with patterns describing files to ignore. + Multiple values are accepted. + Defaults to [.gitignore, .prettierignore]. + --plugin Add a plugin. Multiple plugins can be passed as separate \`--plugin\`s. + Defaults to []. + --with-node-modules Process files inside 'node_modules' directory. + +Editor options: -exports[`throw error with --list-different + --write (stdout) 1`] = `""`; + --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting. + Defaults to -1. + --range-end Format code ending at a given character offset (exclusive). + The range will extend forwards to the end of the selected statement. + Defaults to Infinity. + --range-start Format code starting at a given character offset. + The range will extend backwards to the start of the first line containing the selected statement. + Defaults to 0. -exports[`throw error with --list-different + --write (write) 1`] = `[]`; +Other options: -exports[`throw error with something unexpected (stderr) 1`] = ` -" - Expected at least one target file/dir/glob -" + --cache Only format changed files. Cannot use with --stdin-filepath. + Defaults to false. + --cache-location Path to the cache file. + --cache-strategy + Strategy for the cache to use for detecting changed files. + --check-ignore-pragma Check whether the file's first docblock comment contains '@noprettier' or '@noformat' to determine if it should be formatted. + Defaults to false. + --no-color Do not colorize error messages. + --no-error-on-unmatched-pattern + Prevent errors when pattern is unmatched. + --file-info Extract the following info (as JSON) for a given file path. Reported fields: + * ignored (boolean) - true if file path is filtered by --ignore-path + * inferredParser (string | null) - name of parser inferred from file path + -h, --help Show CLI usage, or details about the given flag. + Example: --help write + -u, --ignore-unknown Ignore unknown files. + --insert-pragma Insert @format pragma into file's first docblock comment. + Defaults to false. + --log-level + What level of logs to report. + Defaults to log. + --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-filepath Path to the file to pretend that stdin comes from. + --support-info Print support information as JSON. + -v, --version Print Prettier version. + +", + "write": [], +} +`; + +exports[`show version with --version 1`] = ` +{ + "stderr": "", + "write": [], +} `; -exports[`throw error with something unexpected (stdout) 1`] = `""`; +exports[`show warning with --help not-found (typo) 1`] = ` +{ + "stderr": "[warn] Unknown flag "parserr", did you mean "parser"?", + "stdout": "--parser -exports[`throw error with something unexpected (write) 1`] = `[]`; + Which parser to use. -exports[`throw unsupported error with --file-info (stderr) 1`] = ` -" - The "--file-info" option is not currently supported, please open an issue on GitHub if you need it -" +Valid options: + + flow Flow + babel JavaScript + babel-flow Flow + babel-ts TypeScript + typescript TypeScript + acorn JavaScript + espree JavaScript + meriyah JavaScript + css CSS + less Less + scss SCSS + json JSON + json5 JSON5 + jsonc JSON with Comments + json-stringify JSON.stringify + graphql GraphQL + markdown Markdown + mdx MDX + vue Vue + yaml YAML + glimmer Ember / Handlebars + html HTML + angular Angular + lwc Lightning Web Components + mjml MJML", + "write": [], +} `; -exports[`throw unsupported error with --file-info (stdout) 1`] = `""`; +exports[`throw error and show usage with something unexpected 1`] = ` +{ + "stderr": "", + "stdout": "Usage: prettier [options] [file/dir/glob ...] + +By default, output is written to stdout. +Stdin is read if it is piped to Prettier and no files are given. + +Output options: -exports[`throw unsupported error with --file-info (write) 1`] = `[]`; + -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). + -w, --write Edit files in-place. (Beware!) -exports[`throw unsupported error with --find-config-path (stderr) 1`] = ` -" - Unknown option: "find-config-path" -" +Format options: + + --arrow-parens + Include parentheses around a sole arrow function parameter. + Defaults to always. + --bracket-same-line Put > of opening tags on the last line instead of on a new line. + Defaults to false. + --no-bracket-spacing Do not print spaces between brackets. + --embedded-language-formatting + Control how Prettier formats quoted code embedded in the file. + Defaults to auto. + --end-of-line + Which end of line characters to apply. + Defaults to lf. + --experimental-operator-position + Where to print operators when binary expressions wrap lines. + Defaults to end. + --no-experimental-ternaries + Default behavior of ternaries; keep question marks on the same line as the consequent. + --html-whitespace-sensitivity + How to handle whitespaces in HTML. + Defaults to css. + --jsx-single-quote Use single quotes in JSX. + Defaults to false. + --object-wrap + How to wrap object literals. + Defaults to preserve. + --parser + Which parser to use. + --print-width The line length where Prettier will try wrap. + Defaults to 80. + --prose-wrap + How to wrap prose. + Defaults to preserve. + --quote-props + Change when properties in objects are quoted. + Defaults to as-needed. + --no-semi Do not print semicolons, except at the beginning of lines which may need them. + --single-attribute-per-line + Enforce single attribute per line in HTML, Vue and JSX. + Defaults to false. + --single-quote Use single quotes instead of double quotes. + Defaults to false. + --tab-width Number of spaces per indentation level. + Defaults to 2. + --trailing-comma + Print trailing commas wherever possible when multi-line. + Defaults to all. + --use-tabs Indent with tabs instead of spaces. + Defaults to false. + --vue-indent-script-and-style + Indent script and style tags in Vue files. + Defaults to false. + +Config options: + + --config Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js). + --no-config Do not look for a configuration file. + --config-precedence + Define in which order config files and CLI options should be evaluated. + Defaults to cli-override. + --no-editorconfig Don't take .editorconfig into account when parsing configuration. + --find-config-path + Find and print the path to a configuration file for the given input file. + --ignore-path Path to a file with patterns describing files to ignore. + Multiple values are accepted. + Defaults to [.gitignore, .prettierignore]. + --plugin Add a plugin. Multiple plugins can be passed as separate \`--plugin\`s. + Defaults to []. + --with-node-modules Process files inside 'node_modules' directory. + +Editor options: + + --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting. + Defaults to -1. + --range-end Format code ending at a given character offset (exclusive). + The range will extend forwards to the end of the selected statement. + Defaults to Infinity. + --range-start Format code starting at a given character offset. + The range will extend backwards to the start of the first line containing the selected statement. + Defaults to 0. + +Other options: + + --cache Only format changed files. Cannot use with --stdin-filepath. + Defaults to false. + --cache-location Path to the cache file. + --cache-strategy + Strategy for the cache to use for detecting changed files. + --check-ignore-pragma Check whether the file's first docblock comment contains '@noprettier' or '@noformat' to determine if it should be formatted. + Defaults to false. + --no-color Do not colorize error messages. + --no-error-on-unmatched-pattern + Prevent errors when pattern is unmatched. + --file-info Extract the following info (as JSON) for a given file path. Reported fields: + * ignored (boolean) - true if file path is filtered by --ignore-path + * inferredParser (string | null) - name of parser inferred from file path + -h, --help Show CLI usage, or details about the given flag. + Example: --help write + -u, --ignore-unknown Ignore unknown files. + --insert-pragma Insert @format pragma into file's first docblock comment. + Defaults to false. + --log-level + What level of logs to report. + Defaults to log. + --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-filepath Path to the file to pretend that stdin comes from. + --support-info Print support information as JSON. + -v, --version Print Prettier version. + +", + "write": [], +} `; -exports[`throw unsupported error with --find-config-path (stdout) 1`] = `""`; +exports[`throw error with --check + --list-different 1`] = ` +{ + "stderr": "[error] Cannot use --check and --list-different together.", + "stdout": "", + "write": [], +} +`; -exports[`throw unsupported error with --find-config-path (write) 1`] = `[]`; +exports[`throw error with --file-info + multiple files 1`] = ` +{ + "stderr": "[error] Cannot use --file-info with multiple files", + "stdout": "", + "write": [], +} +`; -exports[`throw unsupported error with --support-info (stderr) 1`] = ` -" - The "--support-info" option is not currently supported, please open an issue on GitHub if you need it -" +exports[`throw error with --find-config-path + multiple files 1`] = ` +{ + "stderr": "[error] Cannot use --find-config-path with multiple files", + "stdout": "", + "write": [], +} `; -exports[`throw unsupported error with --support-info (stdout) 1`] = `""`; +exports[`throw error with --help not-found 1`] = ` +{ + "stderr": "[error] Invalid --help value. Expected a flag, but received "not-found".", + "stdout": "", + "write": [], +} +`; -exports[`throw unsupported error with --support-info (write) 1`] = `[]`; +exports[`throw error with --write + --debug-check 1`] = ` +{ + "stderr": "[error] Cannot use --write and --debug-check together.", + "stdout": "", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap b/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap index 327d815..0a1d40e 100644 --- a/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap +++ b/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap @@ -1,37 +1,41 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`error on unmatched pattern (stderr) 1`] = `"[error] No files matching the given patterns were found."`; - -exports[`error on unmatched pattern (stdout) 1`] = `""`; - -exports[`error on unmatched pattern (write) 1`] = `[]`; - -exports[`error on unmatched pattern when 2nd glob has no match, by default (stderr) 1`] = `""`; +exports[`error on unmatched pattern 1`] = ` +{ + "stderr": "[error] No files matching the pattern were found: "**/*.toml".", + "stdout": "", + "write": [], +} +`; -exports[`error on unmatched pattern when 2nd glob has no match, by default (stdout) 1`] = ` -"const hello = "there"; +exports[`error on unmatched pattern when 2nd glob has no match 1`] = ` +{ + "stderr": "[error] No files matching the pattern were found: "**/*.toml".", + "stdout": "const hello = "there"; { "hello": "there" } -hello: there" +hello: there", + "write": [], +} `; -exports[`error on unmatched pattern when 2nd glob has no match, by default (write) 1`] = `[]`; - -exports[`no error on unmatched pattern (stderr) 1`] = `""`; - -exports[`no error on unmatched pattern (stdout) 1`] = `"const hello = "there";"`; - -exports[`no error on unmatched pattern (write) 1`] = `[]`; - -exports[`no error on unmatched pattern when 2nd glob has no match, with flag (stderr) 1`] = `""`; +exports[`no error on unmatched pattern 1`] = ` +{ + "stderr": "", + "stdout": "const hello = "there";", + "write": [], +} +`; -exports[`no error on unmatched pattern when 2nd glob has no match, with flag (stdout) 1`] = ` -"const hello = "there"; +exports[`no error on unmatched pattern when 2nd glob has no match 1`] = ` +{ + "stderr": "", + "stdout": "const hello = "there"; { "hello": "there" } -hello: there" +hello: there", + "write": [], +} `; - -exports[`no error on unmatched pattern when 2nd glob has no match, with flag (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/ignore-absolute-path.js.snap b/test/__tests__/__snapshots__/ignore-absolute-path.js.snap index bf1f4a6..2e6692d 100644 --- a/test/__tests__/__snapshots__/ignore-absolute-path.js.snap +++ b/test/__tests__/__snapshots__/ignore-absolute-path.js.snap @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`support absolute filename (stderr) 1`] = `""`; - -exports[`support absolute filename (stdout) 1`] = `"regular-module.js"`; - -exports[`support absolute filename (write) 1`] = `[]`; +exports[`support absolute filename 1`] = ` +{ + "stderr": "", + "stdout": "regular-module.js", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/ignore-emoji.js.snap b/test/__tests__/__snapshots__/ignore-emoji.js.snap index 51dddc3..892c0df 100644 --- a/test/__tests__/__snapshots__/ignore-emoji.js.snap +++ b/test/__tests__/__snapshots__/ignore-emoji.js.snap @@ -1,13 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ignores file name contains emoji (stderr) 1`] = `""`; +exports[`ignores file name contains emoji 1`] = ` +{ + "stderr": "", + "stdout": "not-ignored.js", + "write": [], +} +`; -exports[`ignores file name contains emoji (stdout) 1`] = `"not-ignored.js"`; - -exports[`ignores file name contains emoji (write) 1`] = `[]`; - -exports[`stdin (stderr) 1`] = `""`; - -exports[`stdin (stdout) 1`] = `".name { display: none; }"`; - -exports[`stdin (write) 1`] = `[]`; +exports[`stdin 1`] = ` +{ + "stderr": "", + "stdout": ".name { display: none; }", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap b/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap index 49a61e6..1b5e105 100644 --- a/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap +++ b/test/__tests__/__snapshots__/ignore-in-subdirectories.js.snap @@ -1,33 +1,47 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`formats files when executing in a subdirectory (stderr) 1`] = `""`; - -exports[`formats files when executing in a subdirectory (stderr) 2`] = `""`; - -exports[`formats files when executing in a subdirectory (stdout) 1`] = `"should-not-ignore.js"`; - -exports[`formats files when executing in a subdirectory (stdout) 2`] = `"should-not-ignore.js"`; - -exports[`formats files when executing in a subdirectory (write) 1`] = `[]`; - -exports[`formats files when executing in a subdirectory (write) 2`] = `[]`; - -exports[`formats files when executing in a subdirectory and using stdin (stderr) 1`] = `""`; - -exports[`formats files when executing in a subdirectory and using stdin (write) 1`] = `[]`; - -exports[`ignore files when executing in a subdirectory and using stdin (stderr) 1`] = `""`; - -exports[`ignore files when executing in a subdirectory and using stdin (write) 1`] = `[]`; - -exports[`ignores files when executing in a subdirectory (stderr) 1`] = `""`; - -exports[`ignores files when executing in a subdirectory (stderr) 2`] = `""`; - -exports[`ignores files when executing in a subdirectory (stdout) 1`] = `""`; - -exports[`ignores files when executing in a subdirectory (stdout) 2`] = `""`; - -exports[`ignores files when executing in a subdirectory (write) 1`] = `[]`; - -exports[`ignores files when executing in a subdirectory (write) 2`] = `[]`; +exports[`formats files when executing in a subdirectory 1`] = ` +{ + "stderr": "", + "stdout": "should-not-ignore.js", + "write": [], +} +`; + +exports[`formats files when executing in a subdirectory 2`] = ` +{ + "stderr": "", + "stdout": "should-not-ignore.js", + "write": [], +} +`; + +exports[`formats files when executing in a subdirectory and using stdin 1`] = ` +{ + "stderr": "", + "write": [], +} +`; + +exports[`ignore files when executing in a subdirectory and using stdin 1`] = ` +{ + "stderr": "", + "write": [], +} +`; + +exports[`ignores files when executing in a subdirectory 1`] = ` +{ + "stderr": "", + "stdout": "", + "write": [], +} +`; + +exports[`ignores files when executing in a subdirectory 2`] = ` +{ + "stderr": "", + "stdout": "", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/ignore-relative-path.js.snap b/test/__tests__/__snapshots__/ignore-relative-path.js.snap index 28dc1c3..484ba15 100644 --- a/test/__tests__/__snapshots__/ignore-relative-path.js.snap +++ b/test/__tests__/__snapshots__/ignore-relative-path.js.snap @@ -1,11 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`support relative paths (stderr) 1`] = `""`; - -exports[`support relative paths (stdout) 1`] = ` -"level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss -level1-glob/shouldNotBeIgnored.js -shouldNotBeIgnored.js" +exports[`support relative paths 1`] = ` +{ + "stderr": "", + "stdout": "shouldNotBeIgnored.js +level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss +level1-glob/shouldNotBeIgnored.js", + "write": [], +} `; - -exports[`support relative paths (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/ignore-unknown.js.snap b/test/__tests__/__snapshots__/ignore-unknown.js.snap index 247fef9..89d9bc6 100644 --- a/test/__tests__/__snapshots__/ignore-unknown.js.snap +++ b/test/__tests__/__snapshots__/ignore-unknown.js.snap @@ -1,64 +1,75 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Ignored file (stderr) 1`] = `""`; - -exports[`Ignored file (stdout) 1`] = `""`; - -exports[`Ignored file (write) 1`] = `[]`; - -exports[`None exist file (stderr) 1`] = `"[error] No files matching the given patterns were found."`; - -exports[`None exist file (stdout) 1`] = `""`; - -exports[`None exist file (write) 1`] = `[]`; - -exports[`Not matching pattern (stderr) 1`] = `"[error] No files matching the given patterns were found."`; - -exports[`Not matching pattern (stdout) 1`] = `""`; - -exports[`Not matching pattern (write) 1`] = `[]`; - -exports[`ignore-unknown alias (stdout) 1`] = ` -"javascript.js -override.as-js-file" +exports[`Ignored file 1`] = ` +{ + "stderr": "", + "stdout": "", + "write": [], +} `; -exports[`ignore-unknown check (stderr) 1`] = ` -"[warn] javascript.js -[warn] override.as-js-file -[warn] Code style issues found in 2 files. Run Prettier with --write to fix." +exports[`None exist file 1`] = ` +{ + "stderr": "[error] No files matching the pattern were found: "non-exist-file".", + "stdout": "", + "write": [], +} `; -exports[`ignore-unknown check (stdout) 1`] = `"Checking formatting..."`; +exports[`Not matching pattern 1`] = ` +{ + "stderr": "[error] No files matching the pattern were found: "*.non-exist-pattern".", + "stdout": "", + "write": [], +} +`; -exports[`ignore-unknown check (write) 1`] = `[]`; +exports[`ignore-unknown alias 1`] = ` +{ + "stdout": "javascript.js +override.as-js-file", +} +`; -exports[`ignore-unknown dir (stdout) 1`] = ` -"javascript.js -override.as-js-file" +exports[`ignore-unknown check 1`] = ` +{ + "stderr": "[warn] javascript.js +[warn] override.as-js-file +[warn] Code style issues found in 2 files. Run Prettier with --write to fix.", + "stdout": "Checking formatting...", + "write": [], +} `; -exports[`ignore-unknown pattern (stdout) 1`] = ` -"javascript.js -override.as-js-file" +exports[`ignore-unknown dir 1`] = ` +{ + "stdout": "javascript.js +override.as-js-file", +} `; -exports[`ignore-unknown write (stdout) 1`] = ` -"javascript.js -override.as-js-file" +exports[`ignore-unknown pattern 1`] = ` +{ + "stdout": "javascript.js +override.as-js-file", +} `; -exports[`ignore-unknown write (write) 1`] = ` -[ - { - "content": "const foo = "bar"; +exports[`ignore-unknown write 1`] = ` +{ + "stdout": "javascript.js +override.as-js-file", + "write": [ + { + "content": "const foo = "bar"; ", - "filename": "javascript.js", - }, - { - "content": "const foo = "bar"; + "filename": "javascript.js", + }, + { + "content": "const foo = "bar"; ", - "filename": "override.as-js-file", - }, -] + "filename": "override.as-js-file", + }, + ], +} `; diff --git a/test/__tests__/__snapshots__/ignore-vcs-files.js.snap b/test/__tests__/__snapshots__/ignore-vcs-files.js.snap index b103cd4..b3b5cad 100644 --- a/test/__tests__/__snapshots__/ignore-vcs-files.js.snap +++ b/test/__tests__/__snapshots__/ignore-vcs-files.js.snap @@ -1,17 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`does not ignore files in version control systems, if manually provided (stderr) 1`] = `""`; - -exports[`does not ignore files in version control systems, if manually provided (stdout) 1`] = ` -".hg/file.js -.svn/file.js -file.js" +exports[`ignores files in version control systems 1`] = ` +{ + "stderr": "", + "stdout": "file.js", + "write": [], +} `; - -exports[`does not ignore files in version control systems, if manually provided (write) 1`] = `[]`; - -exports[`ignores files in version control systems, if discovered (stderr) 1`] = `""`; - -exports[`ignores files in version control systems, if discovered (stdout) 1`] = `"file.js"`; - -exports[`ignores files in version control systems, if discovered (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/invalid-ignore.js.snap b/test/__tests__/__snapshots__/invalid-ignore.js.snap index 7ce471b..c75f612 100644 --- a/test/__tests__/__snapshots__/invalid-ignore.js.snap +++ b/test/__tests__/__snapshots__/invalid-ignore.js.snap @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ignores .prettierignore folder (stderr) 1`] = `""`; - -exports[`ignores .prettierignore folder (stdout) 1`] = `""`; - -exports[`ignores .prettierignore folder (write) 1`] = `[]`; +exports[`throw error with invalid ignore 1`] = ` +{ + "stderr": "[error] Unable to read '.prettierignore': EISDIR: illegal operation on a directory, read", + "stdout": "", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/list-different.js.snap b/test/__tests__/__snapshots__/list-different.js.snap index a751bdf..57e5998 100644 --- a/test/__tests__/__snapshots__/list-different.js.snap +++ b/test/__tests__/__snapshots__/list-different.js.snap @@ -1,17 +1,29 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`--list-different works in CI just as in a non-TTY mode (stderr) 1`] = `""`; - -exports[`--list-different works in CI just as in a non-TTY mode (stderr) 2`] = `""`; - -exports[`--list-different works in CI just as in a non-TTY mode (stdout) 1`] = `"unformatted.js"`; - -exports[`--list-different works in CI just as in a non-TTY mode (stdout) 2`] = `"unformatted.js"`; - -exports[`--list-different works in CI just as in a non-TTY mode (write) 1`] = `[]`; - -exports[`--list-different works in CI just as in a non-TTY mode (write) 2`] = `[]`; - -exports[`checks stdin with --list-different (write) 1`] = `[]`; - -exports[`checks stdin with -l (alias for --list-different) (write) 1`] = `[]`; +exports[`--list-different works in CI just as in a non-TTY mode 1`] = ` +{ + "stderr": "", + "stdout": "unformatted.js", + "write": [], +} +`; + +exports[`--list-different works in CI just as in a non-TTY mode 2`] = ` +{ + "stderr": "", + "stdout": "unformatted.js", + "write": [], +} +`; + +exports[`checks stdin with --list-different 1`] = ` +{ + "write": [], +} +`; + +exports[`checks stdin with -l (alias for --list-different) 1`] = ` +{ + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/patterns-glob.js.snap b/test/__tests__/__snapshots__/patterns-glob.js.snap index 510a4c6..8d3ec1a 100644 --- a/test/__tests__/__snapshots__/patterns-glob.js.snap +++ b/test/__tests__/__snapshots__/patterns-glob.js.snap @@ -1,104 +1,115 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`fixtures-1: Should match all files (stderr) 1`] = `""`; - -exports[`fixtures-1: Should match all files (stdout) 1`] = ` -"!file.js +exports[`fixtures-1: Should match all files 1`] = ` +{ + "stderr": "", + "stdout": "!file.js a.js -b.js" +b.js", + "write": [], +} `; -exports[`fixtures-1: Should match all files (write) 1`] = `[]`; - -exports[`fixtures-1: Should match files except \`a.js\` (stderr) 1`] = `""`; - -exports[`fixtures-1: Should match files except \`a.js\` (stdout) 1`] = ` -"!file.js -b.js" +exports[`fixtures-1: Should match files except \`a.js\` 1`] = ` +{ + "stderr": "", + "stdout": "!file.js +b.js", + "write": [], +} `; -exports[`fixtures-1: Should match files except \`a.js\` (write) 1`] = `[]`; - -exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` (stderr) 1`] = `""`; - -exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` (stdout) 1`] = ` -"!b.js -a.js" +exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` 1`] = ` +{ + "stderr": "", + "stdout": "!b.js +a.js", + "write": [], +} `; -exports[`fixtures-2: Should match \`a.js\` and \`!b.js\` (write) 1`] = `[]`; - -exports[`fixtures-2: Should match all js files and all supported files in the '!dir.js' directory (stderr) 1`] = `""`; - -exports[`fixtures-2: Should match all js files and all supported files in the '!dir.js' directory (stdout) 1`] = ` -"!b.js +exports[`fixtures-2: Should match all js files and all supported files in the '!dir.js' directory 1`] = ` +{ + "stderr": "", + "stdout": "!b.js +a.js !dir.js/1.css -!dir.js/2.css -a.js" +!dir.js/2.css", + "write": [], +} `; -exports[`fixtures-2: Should match all js files and all supported files in the '!dir.js' directory (write) 1`] = `[]`; - -exports[`fixtures-2: Should only match \`!b.js\` (stderr) 1`] = `""`; - -exports[`fixtures-2: Should only match \`!b.js\` (stdout) 1`] = `"!b.js"`; +exports[`fixtures-2: Should only match \`!b.js\` 1`] = ` +{ + "stderr": "", + "stdout": "!b.js", + "write": [], +} +`; -exports[`fixtures-2: Should only match \`!b.js\` (write) 1`] = `[]`; +exports[`fixtures-3: Should exclude \`.svn\` (existing) 1`] = ` +{ + "stderr": "", + "stdout": "outside.js", + "write": [], +} +`; -exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` (stderr) 1`] = `""`; +exports[`fixtures-3: Should exclude \`.svn\` (nonexisting) 1`] = ` +{ + "stderr": "", + "stdout": "outside.js", + "write": [], +} +`; -exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` (stdout) 1`] = ` -"dir/inside.js +exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` 1`] = ` +{ + "stderr": "", + "stdout": "dir/inside.js dir/node_modules/in-node_modules.js -outside.js" +outside.js", + "write": [], +} `; -exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` (write) 1`] = `[]`; - -exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) (stderr) 1`] = `""`; - -exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) (stdout) 1`] = ` -"dir/.svn/in-svn.js -outside.js" +exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` 1`] = ` +{ + "stderr": "", + "stdout": "dir/inside.js +outside.js", + "write": [], +} `; -exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) (write) 1`] = `[]`; - -exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) (stderr) 1`] = `""`; - -exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) (stdout) 1`] = `"outside.js"`; - -exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) (write) 1`] = `[]`; - -exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` (stderr) 1`] = `""`; - -exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` (stdout) 1`] = ` -"dir/inside.js -outside.js" +exports[`fixtures-4: Should match \`level-1.js\` 1`] = ` +{ + "stderr": "", + "stdout": "0/level-1.js", + "write": [], +} `; -exports[`fixtures-3: Should only match \`outside.js\` and \`dir/inside.js\` (write) 1`] = `[]`; - -exports[`fixtures-4: Should match \`level-1.js\` #2 (stderr) 1`] = `""`; - -exports[`fixtures-4: Should match \`level-1.js\` #2 (stdout) 1`] = `"0/level-1.js"`; - -exports[`fixtures-4: Should match \`level-1.js\` #2 (write) 1`] = `[]`; - -exports[`fixtures-4: Should match \`level-1.js\` #3 (stderr) 1`] = `""`; - -exports[`fixtures-4: Should match \`level-1.js\` #3 (stdout) 1`] = `"0/level-1.js"`; - -exports[`fixtures-4: Should match \`level-1.js\` #3 (write) 1`] = `[]`; - -exports[`fixtures-4: Should match \`level-1.js\` (stderr) 1`] = `""`; - -exports[`fixtures-4: Should match \`level-1.js\` (stdout) 1`] = `"0/level-1.js"`; - -exports[`fixtures-4: Should match \`level-1.js\` (write) 1`] = `[]`; - -exports[`should not ignore file paths contains object prototype keys (stderr) 1`] = `""`; +exports[`fixtures-4: Should match \`level-1.js\` #2 1`] = ` +{ + "stderr": "", + "stdout": "0/level-1.js", + "write": [], +} +`; -exports[`should not ignore file paths contains object prototype keys (stdout) 1`] = `"constructor/should-be-formatted.js"`; +exports[`fixtures-4: Should match \`level-1.js\` #3 1`] = ` +{ + "stderr": "", + "stdout": "0/level-1.js", + "write": [], +} +`; -exports[`should not ignore file paths contains object prototype keys (write) 1`] = `[]`; +exports[`should not ignore file paths contains object prototype keys 1`] = ` +{ + "stderr": "", + "stdout": "constructor/should-be-formatted.js", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/patterns.js.snap b/test/__tests__/__snapshots__/patterns.js.snap index d2bc8ff..34d65b1 100644 --- a/test/__tests__/__snapshots__/patterns.js.snap +++ b/test/__tests__/__snapshots__/patterns.js.snap @@ -1,82 +1,83 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`exits with an informative message when there are no patterns provided (stderr) 1`] = ` -" - Expected at least one target file/dir/glob -" -`; - -exports[`exits with an informative message when there are no patterns provided (stdout) 1`] = `""`; - -exports[`exits with an informative message when there are no patterns provided (write) 1`] = `[]`; - -exports[`multiple patterns (stderr) 1`] = `""`; - -exports[`multiple patterns (stdout) 1`] = ` -"directory/file.js +exports[`multiple patterns 1`] = ` +{ + "stderr": "", + "stdout": "directory/file.js directory/nested-directory/nested-directory-file.js other-directory/file.js -other-directory/nested-directory/nested-directory-file.js" +other-directory/nested-directory/nested-directory-file.js", + "write": [], +} `; -exports[`multiple patterns (write) 1`] = `[]`; - -exports[`multiple patterns with a negated pattern (stderr) 1`] = `""`; - -exports[`multiple patterns with a negated pattern (stdout) 1`] = ` -"directory/file.js +exports[`multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag 1`] = ` +{ + "stderr": "", + "stdout": "node_modules/node-module.js other-directory/file.js +other-directory/nested-directory/nested-directory-file.js other-regular-modules.js -regular-module.js" +regular-module.js", + "write": [], +} `; -exports[`multiple patterns with a negated pattern (write) 1`] = `[]`; - -exports[`multiple patterns with a negated pattern and leading \`./\`, ignores node_modules by default (stderr) 1`] = `""`; - -exports[`multiple patterns with a negated pattern and leading \`./\`, ignores node_modules by default (stdout) 1`] = ` -"other-directory/file.js +exports[`multiple patterns by with ignore pattern, ignores node_modules by default 1`] = ` +{ + "stderr": "", + "stdout": "other-directory/file.js other-directory/nested-directory/nested-directory-file.js other-regular-modules.js -regular-module.js" +regular-module.js", + "write": [], +} `; -exports[`multiple patterns with a negated pattern and leading \`./\`, ignores node_modules by default (write) 1`] = `[]`; - -exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag (stderr) 1`] = `""`; - -exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag (stdout) 1`] = ` -"node_modules/node-module.js -other-directory/file.js +exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js 1`] = ` +{ + "stderr": "", + "stdout": "other-directory/file.js other-directory/nested-directory/nested-directory-file.js other-regular-modules.js -regular-module.js" +regular-module.js", + "write": [], +} `; -exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag (write) 1`] = `[]`; - -exports[`multiple patterns with a negated pattern, ignores node_modules by default (stderr) 1`] = `""`; - -exports[`multiple patterns with a negated pattern, ignores node_modules by default (stdout) 1`] = ` -"other-directory/file.js -other-directory/nested-directory/nested-directory-file.js +exports[`multiple patterns with ignore nested directories pattern 1`] = ` +{ + "stderr": "", + "stdout": "directory/file.js +other-directory/file.js other-regular-modules.js -regular-module.js" +regular-module.js", + "write": [], +} `; -exports[`multiple patterns with a negated pattern, ignores node_modules by default (write) 1`] = `[]`; - -exports[`multiple patterns with an extra non-existent pattern (stderr) 1`] = `""`; - -exports[`multiple patterns with an extra non-existent pattern (stdout) 1`] = ` -"directory/file.js -directory/nested-directory/nested-directory-file.js" +exports[`multiple patterns with non exists pattern 1`] = ` +{ + "stderr": "[error] No files matching the pattern were found: "non-existent.js".", + "stdout": "directory/file.js +directory/nested-directory/nested-directory-file.js", + "write": [], +} `; -exports[`multiple patterns with an extra non-existent pattern (write) 1`] = `[]`; - -exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches (stderr) 1`] = `"[error] No files matching the given patterns were found."`; - -exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches (stdout) 1`] = `""`; +exports[`multiple patterns, throw error and exit with non zero code on non existing files 1`] = ` +{ + "stderr": "[error] No files matching the pattern were found: "non-existent.js". +[error] No files matching the pattern were found: "other-non-existent.js".", + "stdout": "", + "write": [], +} +`; -exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches (write) 1`] = `[]`; +exports[`no errors on empty patterns 1`] = ` +{ + "stderr": "", + "stdout": "", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/plugin-options-string.js.snap b/test/__tests__/__snapshots__/plugin-options-string.js.snap index 9b1cc15..8d7b679 100644 --- a/test/__tests__/__snapshots__/plugin-options-string.js.snap +++ b/test/__tests__/__snapshots__/plugin-options-string.js.snap @@ -1,7 +1,43 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`show detailed external option with \`--help foo-string\` 1`] = ` +{ + "stderr": "", + "stdout": "--foo-string + + foo description + +Default: bar", + "write": [], +} +`; + exports[`show external options with \`--help\` 1`] = ` -" --parser - --foo-string foo description - Defaults to "bar"" +"Snapshot Diff: +- First value ++ Second value + +@@ -27,19 +27,21 @@ + --experimental-operator-position + Where to print operators when binary expressions wrap lines. + Defaults to end. + --no-experimental-ternaries + Default behavior of ternaries; keep question marks on the same line as the consequent. ++ --foo-string foo description ++ Defaults to bar. + --html-whitespace-sensitivity + How to handle whitespaces in HTML. + Defaults to css. + --jsx-single-quote Use single quotes in JSX. + Defaults to false. + --object-wrap + How to wrap object literals. + Defaults to preserve. +- --parser ++ --parser + Which parser to use. + --print-width The line length where Prettier will try wrap. + Defaults to 80. + --prose-wrap + How to wrap prose." `; diff --git a/test/__tests__/__snapshots__/plugin-options.js.snap b/test/__tests__/__snapshots__/plugin-options.js.snap index fb9a753..dd11d78 100644 --- a/test/__tests__/__snapshots__/plugin-options.js.snap +++ b/test/__tests__/__snapshots__/plugin-options.js.snap @@ -1,7 +1,87 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`include plugin's parsers to the values of the \`parser\` option\` 1`] = ` +{ + "stderr": "", + "stdout": "--parser + + Which parser to use. + +Valid options: + + flow Flow + babel JavaScript + babel-flow Flow + babel-ts TypeScript + typescript TypeScript + acorn JavaScript + espree JavaScript + meriyah JavaScript + css CSS + less Less + scss SCSS + json JSON + json5 JSON5 + jsonc JSON with Comments + json-stringify JSON.stringify + graphql GraphQL + markdown Markdown + mdx MDX + vue Vue + yaml YAML + glimmer Ember / Handlebars + html HTML + angular Angular + lwc Lightning Web Components + mjml MJML + foo-parser foo (plugin: ./plugin.cjs)", + "write": [], +} +`; + +exports[`show detailed external option with \`--help foo-option\` 1`] = ` +{ + "stderr": "", + "stdout": "--foo-option + + foo description + +Valid options: + + bar bar description + baz baz description + +Default: bar", + "write": [], +} +`; + exports[`show external options with \`--help\` 1`] = ` -" --parser - --foo-option foo description - Defaults to "bar"" +"Snapshot Diff: +- First value ++ Second value + +@@ -27,19 +27,21 @@ + --experimental-operator-position + Where to print operators when binary expressions wrap lines. + Defaults to end. + --no-experimental-ternaries + Default behavior of ternaries; keep question marks on the same line as the consequent. ++ --foo-option foo description ++ Defaults to bar. + --html-whitespace-sensitivity + How to handle whitespaces in HTML. + Defaults to css. + --jsx-single-quote Use single quotes in JSX. + Defaults to false. + --object-wrap + How to wrap object literals. + Defaults to preserve. +- --parser ++ --parser + Which parser to use. + --print-width The line length where Prettier will try wrap. + Defaults to 80. + --prose-wrap + How to wrap prose." `; diff --git a/test/__tests__/__snapshots__/print-code.js.snap b/test/__tests__/__snapshots__/print-code.js.snap index c5943c8..132bca1 100644 --- a/test/__tests__/__snapshots__/print-code.js.snap +++ b/test/__tests__/__snapshots__/print-code.js.snap @@ -1,5 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Line breaking after filepath with errors (stdout) 1`] = `"foo();"`; +exports[`Line breaking after filepath with errors 1`] = ` +{ + "stdout": "ignored.js +[[called readline.clearLine(process.stdout)]] +foo( +)", +} +`; -exports[`Line breaking after filepath with errors (stdout) 2`] = `"foo();"`; +exports[`Line breaking after filepath with errors 2`] = ` +{ + "stdout": "not-ignored.js +[[called readline.clearLine(process.stdout)]] +foo();", +} +`; diff --git a/test/__tests__/__snapshots__/skip-folders.js.snap b/test/__tests__/__snapshots__/skip-folders.js.snap index 9ffde85..b386f80 100644 --- a/test/__tests__/__snapshots__/skip-folders.js.snap +++ b/test/__tests__/__snapshots__/skip-folders.js.snap @@ -1,15 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`skip folders passed specifically (stdout) 1`] = ` -"a/file.js -b/file.js" +exports[`skip folders passed specifically 1`] = ` +{ + "stdout": "a/file.js +b/file.js", + "write": [], +} `; -exports[`skip folders passed specifically (write) 1`] = `[]`; - -exports[`skips folders in glob (stdout) 1`] = ` -"a/file.js -b/file.js" +exports[`skips folders in glob 1`] = ` +{ + "stdout": "a/file.js +b/file.js", + "write": [], +} `; - -exports[`skips folders in glob (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/syntax-error.js.snap b/test/__tests__/__snapshots__/syntax-error.js.snap index 48872f7..6296e8f 100644 --- a/test/__tests__/__snapshots__/syntax-error.js.snap +++ b/test/__tests__/__snapshots__/syntax-error.js.snap @@ -1,11 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`exits with non-zero code when input has a syntax error (stderr) 1`] = ` -"[error] SyntaxError: Missing semicolon. (1:2) +exports[`exits with non-zero code when input has a syntax error 1`] = ` +{ + "stderr": "[error] stdin: SyntaxError: Missing semicolon. (1:2) [error] > 1 | a.2 -[error] | ^" +[error] | ^", + "stdout": "", + "write": [], +} `; - -exports[`exits with non-zero code when input has a syntax error (stdout) 1`] = `""`; - -exports[`exits with non-zero code when input has a syntax error (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/with-node-modules.js.snap b/test/__tests__/__snapshots__/with-node-modules.js.snap index 851de77..5e8abe0 100644 --- a/test/__tests__/__snapshots__/with-node-modules.js.snap +++ b/test/__tests__/__snapshots__/with-node-modules.js.snap @@ -1,41 +1,50 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`does not ignore node_modules for manual file list (stderr) 1`] = `""`; - -exports[`does not ignore node_modules for manual file list (stdout) 1`] = ` -"nested/node_modules/node-module.js +exports[`doesn't ignore node_modules with --with-node-modules flag 1`] = ` +{ + "stderr": "", + "stdout": "nested/node_modules/node-module.js node_modules/node-module.js not_node_modules/file.js -regular-module.js" +regular-module.js", + "write": [], +} `; -exports[`does not ignore node_modules for manual file list (write) 1`] = `[]`; - -exports[`doesn't ignore node_modules with --with-node-modules flag (stderr) 1`] = `""`; - -exports[`doesn't ignore node_modules with --with-node-modules flag (stdout) 1`] = ` -"nested/node_modules/node-module.js -node_modules/node-module.js +exports[`doesn't ignore node_modules with --with-node-modules flag for file list 1`] = ` +{ + "stderr": "", + "stdout": "node_modules/node-module.js not_node_modules/file.js -regular-module.js" +nested/node_modules/node-module.js +regular-module.js", + "write": [], +} `; -exports[`doesn't ignore node_modules with --with-node-modules flag (write) 1`] = `[]`; - -exports[`ignores node_modules by default (stderr) 1`] = `""`; - -exports[`ignores node_modules by default (stdout) 1`] = ` -"not_node_modules/file.js -regular-module.js" +exports[`ignores node_modules by default 1`] = ` +{ + "stderr": "", + "stdout": "not_node_modules/file.js +regular-module.js", + "write": [], +} `; -exports[`ignores node_modules by default (write) 1`] = `[]`; - -exports[`ignores node_modules by with ./**/*.js (stderr) 1`] = `""`; - -exports[`ignores node_modules by with ./**/*.js (stdout) 1`] = ` -"not_node_modules/file.js -regular-module.js" +exports[`ignores node_modules by default for file list 1`] = ` +{ + "stderr": "", + "stdout": "not_node_modules/file.js +regular-module.js", + "write": [], +} `; -exports[`ignores node_modules by with ./**/*.js (write) 1`] = `[]`; +exports[`ignores node_modules by with ./**/*.js 1`] = ` +{ + "stderr": "", + "stdout": "not_node_modules/file.js +regular-module.js", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/with-parser-inference.js.snap b/test/__tests__/__snapshots__/with-parser-inference.js.snap index 5381c1f..5a32a72 100644 --- a/test/__tests__/__snapshots__/with-parser-inference.js.snap +++ b/test/__tests__/__snapshots__/with-parser-inference.js.snap @@ -1,53 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`infers parser from filename (.prettierrc) (stdout) 1`] = `"{}"`; - -exports[`infers parser from filename (.stylelintrc YAML) (stdout) 1`] = `"extends: """`; - -exports[`infers parser from filename (.stylelintrc) (stdout) 1`] = `"{}"`; - -exports[`infers parser from filename (jakefile) (stdout) 1`] = `"let foo = (x = 1) => x;"`; - -exports[`infers parser from filename (lintstagedrc YAML) (stdout) 1`] = ` -""*": - - your-cmd" -`; - -exports[`infers parser from filename (lintstagedrc) (stdout) 1`] = `"{ "*": "your-cmd" }"`; - -exports[`infers parser from filename (swcrc) (stdout) 1`] = ` -"{ - "jsc": { - // Requires v1.2.50 or upper and requires target to be es2016 or upper. - "keepClassNames": false - } -}" -`; - -exports[`infers postcss parser (stderr) 1`] = `""`; - -exports[`infers postcss parser (stdout) 1`] = ` -"/* JavaScript */ +exports[`infers postcss parser 1`] = ` +{ + "stderr": "", + "stdout": "/* JavaScript */ "use strict"; /* Stylesheet */ * { outline: none; -}" +}", + "write": [], +} `; -exports[`infers postcss parser (write) 1`] = `[]`; - -exports[`infers postcss parser with --check (stderr) 1`] = `""`; - -exports[`infers postcss parser with --check (stdout) 1`] = ` -"Checking formatting... -All matched files use Prettier code style!" +exports[`infers postcss parser with --check 1`] = ` +{ + "stderr": "", + "stdout": "Checking formatting... +All matched files use Prettier code style!", + "write": [], +} `; -exports[`infers postcss parser with --check (write) 1`] = `[]`; - -exports[`infers postcss parser with --list-different (stderr) 1`] = `""`; - -exports[`infers postcss parser with --list-different (stdout) 1`] = `""`; - -exports[`infers postcss parser with --list-different (write) 1`] = `[]`; +exports[`infers postcss parser with --list-different 1`] = ` +{ + "stderr": "", + "stdout": "", + "write": [], +} +`; diff --git a/test/__tests__/__snapshots__/with-shebang.js.snap b/test/__tests__/__snapshots__/with-shebang.js.snap index cd5382c..4f57f17 100644 --- a/test/__tests__/__snapshots__/with-shebang.js.snap +++ b/test/__tests__/__snapshots__/with-shebang.js.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`preserves shebang (stderr) 1`] = `""`; - -exports[`preserves shebang (stdout) 1`] = ` -"#!/usr/bin/env node -"use strict";" +exports[`preserves shebang 1`] = ` +{ + "stderr": "", + "stdout": "#!/usr/bin/env node +"use strict";", + "write": [], +} `; - -exports[`preserves shebang (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/write.js.snap b/test/__tests__/__snapshots__/write.js.snap index 15a6f0c..ddeed12 100644 --- a/test/__tests__/__snapshots__/write.js.snap +++ b/test/__tests__/__snapshots__/write.js.snap @@ -1,41 +1,45 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`do not write file with --write + formatted file (stderr) 1`] = `""`; - -exports[`do not write file with --write + formatted file (stdout) 1`] = `"formatted.js 0ms (unchanged)"`; +exports[`do not write file with --write + formatted file 1`] = ` +{ + "stderr": "", + "stdout": "formatted.js 0ms (unchanged)", +} +`; -exports[`do not write file with --write + invalid file (stderr) 1`] = ` -"[error] invalid.js: SyntaxError: Unexpected token (1:17) +exports[`do not write file with --write + invalid file 1`] = ` +{ + "stderr": "[error] invalid.js: SyntaxError: Unexpected token (1:17) [error] > 1 | this is invalid! -[error] | ^" +[error] | ^", + "stdout": "", +} `; -exports[`do not write file with --write + invalid file (stdout) 1`] = `""`; - -exports[`write file with --write + unformatted file (stderr) 1`] = `""`; - -exports[`write file with --write + unformatted file (stdout) 1`] = `"unformatted.js 0ms"`; - -exports[`write file with --write + unformatted file (write) 1`] = ` -[ - { - "content": "var x = 1; +exports[`write file with --write + unformatted file 1`] = ` +{ + "stderr": "", + "stdout": "unformatted.js 0ms", + "write": [ + { + "content": "var x = 1; ", - "filename": "unformatted.js", - }, -] + "filename": "unformatted.js", + }, + ], +} `; -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`] = ` -[ - { - "content": "var x = 1; +exports[`write file with -w + unformatted file 1`] = ` +{ + "stderr": "", + "stdout": "unformatted.js 0ms", + "write": [ + { + "content": "var x = 1; ", - "filename": "unformatted.js", - }, -] + "filename": "unformatted.js", + }, + ], +} `; diff --git a/test/utils.js b/test/utils.js index 10dd8cc..9d81509 100644 --- a/test/utils.js +++ b/test/utils.js @@ -134,24 +134,33 @@ async function runCommand(dir, args, options) { return { cwd, status, stdout, stderr, write }; } -async function runTest(name, expected, getResult, options) { +async function runTest(tests, getResult, options) { const title = options.title || ""; - test(`${title}(${name})`, async () => { + test(title, async () => { let result = await getResult(); - let value = result[name]; - if (expected !== undefined) { - if (name === "status" && expected === "non-zero") { - expect(value).not.toBe(0); - } else if (typeof expected === "function") { - expected(value); - } else { - if (typeof value === "string") { - value = value.replaceAll(result.cwd, "$CWD"); + let snapshot; + for (const name of ["status", "stdout", "stderr", "write"]) { + let value = result[name]; + const expected = tests[name]; + if (expected !== undefined) { + if (name === "status" && expected === "non-zero") { + expect(value).not.toBe(0); + } else if (typeof expected === "function") { + expected(value); + } else { + if (typeof value === "string") { + value = value.replaceAll(result.cwd, "$CWD"); + } + expect(value).toEqual(expected); } - expect(value).toEqual(expected); + } else { + snapshot ??= {}; + snapshot[name] = value; } - } else { - expect(value).toMatchSnapshot(); + } + + if (snapshot) { + expect(snapshot).toMatchSnapshot(); } }); } @@ -173,13 +182,7 @@ function runCli(dir, args = [], options = {}) { get write() { return getResult().then((result) => result.write); }, - test: (tests) => { - for (const name of ["status", "stdout", "stderr", "write"]) { - const expected = tests[name]; - runTest(name, expected, getResult, options); - } - return result; - }, + test: (tests) => runTest(tests, getResult, options), then: (onFulfilled, onRejected) => { return getResult().then(onFulfilled, onRejected); }, From 75afc652d6b8f671c04b11bb1efeeb033ff40581 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 22 Apr 2025 15:29:03 +0000 Subject: [PATCH 2/2] Regenerate snapshots --- .../__snapshots__/arg-parsing.js.snap | 44 +- test/__tests__/__snapshots__/check.js.snap | 4 +- .../__snapshots__/early-exit.js.snap | 474 ++++++------------ .../error-on-unmatched-pattern.js.snap | 8 +- .../__snapshots__/ignore-emoji.js.snap | 8 - .../__snapshots__/ignore-folder.js.snap | 26 +- .../ignore-relative-path.js.snap | 6 +- .../__snapshots__/ignore-unknown.js.snap | 4 +- .../__snapshots__/ignore-vcs-files.js.snap | 12 +- .../__snapshots__/invalid-ignore.js.snap | 4 +- .../__snapshots__/patterns-glob.js.snap | 21 +- test/__tests__/__snapshots__/patterns.js.snap | 48 +- .../plugin-options-string.js.snap | 42 +- .../__snapshots__/plugin-options.js.snap | 86 +--- .../__snapshots__/print-code.js.snap | 9 +- .../__snapshots__/syntax-error.js.snap | 2 +- .../__snapshots__/with-node-modules.js.snap | 17 +- .../with-parser-inference.js.snap | 48 ++ test/__tests__/__snapshots__/write.js.snap | 45 -- 19 files changed, 301 insertions(+), 607 deletions(-) delete mode 100644 test/__tests__/__snapshots__/write.js.snap diff --git a/test/__tests__/__snapshots__/arg-parsing.js.snap b/test/__tests__/__snapshots__/arg-parsing.js.snap index 58cb29f..5873143 100644 --- a/test/__tests__/__snapshots__/arg-parsing.js.snap +++ b/test/__tests__/__snapshots__/arg-parsing.js.snap @@ -15,14 +15,6 @@ exports[`boolean flags do not swallow the next argument 1`] = ` } `; -exports[`deprecated option values are warned 1`] = ` -{ - "stderr": "[warn] --jsx-bracket-same-line is deprecated.", - "stdout": "console.log("could be single quote and without semi");", - "write": [], -} -`; - exports[`negated options work 1`] = ` { "stderr": "", @@ -64,39 +56,31 @@ exports[`number file/dir 5`] = ` } `; -exports[`options with \`cliName\` should not allow to pass directly 1`] = ` +exports[`unknown negated options are errored 1`] = ` { - "stdout": "prettier();", -} -`; - -exports[`options with \`cliName\` should not allow to pass directly 2`] = ` -{ - "stderr": "[warn] Ignored unknown option --filepath=file.js. -[error] No parser and no file path given, couldn't infer a parser.", + "stderr": " + Unknown option: "unknown" +", "stdout": "", -} -`; - -exports[`unknown negated options are warned 1`] = ` -{ - "stderr": "[warn] Ignored unknown option --no-unknown.", - "stdout": "console.log("could be single quote and without semi");", "write": [], } `; -exports[`unknown options are warned 1`] = ` +exports[`unknown options are errored 1`] = ` { - "stderr": "[warn] Ignored unknown option --unknown.", - "stdout": "console.log("could be single quote and without semi");", + "stderr": " + Unknown option: "unknown" +", + "stdout": "", "write": [], } `; -exports[`unknown options not suggestion \`_\` 1`] = ` +exports[`unknown options may trigger a suggestion \`_\` 1`] = ` { - "stderr": "[warn] Ignored unknown option -a. Did you mean -c?", - "stdout": "console.log("could be single quote and without semi");", + "stderr": " + Unknown option: "a". Did you mean "v"? +", + "stdout": "", } `; diff --git a/test/__tests__/__snapshots__/check.js.snap b/test/__tests__/__snapshots__/check.js.snap index 39b0e8f..5c4ab15 100644 --- a/test/__tests__/__snapshots__/check.js.snap +++ b/test/__tests__/__snapshots__/check.js.snap @@ -13,7 +13,7 @@ exports[`--checks should print the number of files that need formatting 1`] = ` exports[`--checks works in CI just as in a non-TTY mode 1`] = ` { "stderr": "[warn] unformatted.js -[warn] Code style issues found in the above file. Run Prettier with --write to fix.", +[warn] Code style issues found in 1 file. Run Prettier with --write to fix.", "stdout": "Checking formatting...", "write": [], } @@ -22,7 +22,7 @@ exports[`--checks works in CI just as in a non-TTY mode 1`] = ` exports[`--checks works in CI just as in a non-TTY mode 2`] = ` { "stderr": "[warn] unformatted.js -[warn] Code style issues found in the above file. Run Prettier with --write to fix.", +[warn] Code style issues found in 1 file. Run Prettier with --write to fix.", "stdout": "Checking formatting...", "write": [], } diff --git a/test/__tests__/__snapshots__/early-exit.js.snap b/test/__tests__/__snapshots__/early-exit.js.snap index d04a83b..6f53037 100644 --- a/test/__tests__/__snapshots__/early-exit.js.snap +++ b/test/__tests__/__snapshots__/early-exit.js.snap @@ -1,156 +1,137 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`show detailed usage with --help l (alias) 1`] = ` -{ - "stderr": "", - "stdout": "-l, --list-different - - Print the names of files that are different from Prettier's formatting (see also --check).", - "write": [], -} -`; - -exports[`show detailed usage with plugin options (manual resolution) 1`] = ` -{ - "stderr": "", - "stdout": "--tab-width - - Number of spaces per indentation level. - -Default: 2 -Plugin defaults: -* ../plugins/automatic/node_modules/prettier-plugin-bar/index.js: 4", - "write": [], -} -`; - exports[`show usage with --help 1`] = ` { "stderr": "", - "stdout": "Usage: prettier [options] [file/dir/glob ...] - -By default, output is written to stdout. -Stdin is read if it is piped to Prettier and no files are given. - -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). - -w, --write Edit files in-place. (Beware!) - -Format options: - - --arrow-parens - Include parentheses around a sole arrow function parameter. - Defaults to always. - --bracket-same-line Put > of opening tags on the last line instead of on a new line. - Defaults to false. - --no-bracket-spacing Do not print spaces between brackets. - --embedded-language-formatting - Control how Prettier formats quoted code embedded in the file. - Defaults to auto. - --end-of-line - Which end of line characters to apply. - Defaults to lf. - --experimental-operator-position - Where to print operators when binary expressions wrap lines. - Defaults to end. - --no-experimental-ternaries - Default behavior of ternaries; keep question marks on the same line as the consequent. - --html-whitespace-sensitivity - How to handle whitespaces in HTML. - Defaults to css. - --jsx-single-quote Use single quotes in JSX. - Defaults to false. - --object-wrap - How to wrap object literals. - Defaults to preserve. - --parser - Which parser to use. - --print-width The line length where Prettier will try wrap. - Defaults to 80. - --prose-wrap - How to wrap prose. - Defaults to preserve. - --quote-props - Change when properties in objects are quoted. - Defaults to as-needed. - --no-semi Do not print semicolons, except at the beginning of lines which may need them. - --single-attribute-per-line - Enforce single attribute per line in HTML, Vue and JSX. - Defaults to false. - --single-quote Use single quotes instead of double quotes. - Defaults to false. - --tab-width Number of spaces per indentation level. - Defaults to 2. - --trailing-comma - Print trailing commas wherever possible when multi-line. - Defaults to all. - --use-tabs Indent with tabs instead of spaces. - Defaults to false. - --vue-indent-script-and-style - Indent script and style tags in Vue files. - Defaults to false. - -Config options: - - --config Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js). - --no-config Do not look for a configuration file. - --config-precedence - Define in which order config files and CLI options should be evaluated. - Defaults to cli-override. - --no-editorconfig Don't take .editorconfig into account when parsing configuration. - --find-config-path - Find and print the path to a configuration file for the given input file. - --ignore-path Path to a file with patterns describing files to ignore. - Multiple values are accepted. - Defaults to [.gitignore, .prettierignore]. - --plugin Add a plugin. Multiple plugins can be passed as separate \`--plugin\`s. - Defaults to []. - --with-node-modules Process files inside 'node_modules' directory. - -Editor options: - - --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting. - Defaults to -1. - --range-end Format code ending at a given character offset (exclusive). - The range will extend forwards to the end of the selected statement. - Defaults to Infinity. - --range-start Format code starting at a given character offset. - The range will extend backwards to the start of the first line containing the selected statement. - Defaults to 0. - -Other options: - - --cache Only format changed files. Cannot use with --stdin-filepath. - Defaults to false. - --cache-location Path to the cache file. - --cache-strategy - Strategy for the cache to use for detecting changed files. - --check-ignore-pragma Check whether the file's first docblock comment contains '@noprettier' or '@noformat' to determine if it should be formatted. - Defaults to false. - --no-color Do not colorize error messages. - --no-error-on-unmatched-pattern - Prevent errors when pattern is unmatched. - --file-info Extract the following info (as JSON) for a given file path. Reported fields: - * ignored (boolean) - true if file path is filtered by --ignore-path - * inferredParser (string | null) - name of parser inferred from file path - -h, --help Show CLI usage, or details about the given flag. - Example: --help write - -u, --ignore-unknown Ignore unknown files. - --insert-pragma Insert @format pragma into file's first docblock comment. - Defaults to false. - --log-level - What level of logs to report. - Defaults to log. - --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-filepath Path to the file to pretend that stdin comes from. - --support-info Print support information as JSON. - -v, --version Print Prettier version. - -", + "stdout": " + prettier 3.3.3 + + USAGE + + prettier [file/dir/glob...] [options] + prettier "src/**/*.js" --check + prettier "src/**/*.js" -l --no-cache + prettier "src/**/*.js" --write --no-parallel + prettier ./path/to/target/file.js --cache-location ./path/to/cache/file.json + + ARGUMENTS + + [file/dir/glob...] Files, directories or globs to format + + OUTPUT OPTIONS + + --check, -c Check if the given files are formatted, print a human-friendly summary (see also --list-different) + --list-different, -l Print the names of files that are different from Prettier's formatting (see also --check) + --write, -w Edit files in-place (Beware!) + + FORMAT OPTIONS + + --arrow-parens + Include parentheses around a sole arrow function parameter + Defaults to "always" + --bracket-same-line Put ">" of opening tags on the last line instead of on a new line + Defaults to "false" + --no-bracket-spacing Do not print spaces between brackets + Defaults to "true" + --embedded-language-formatting + Control how Prettier formats quoted code embedded in the file + Defaults to "auto" + --end-of-line + Which end of line characters to apply + Defaults to "lf" + --experimental-operator-position + Where to print operators when binary expressions wrap lines + Defaults to "end" + --experimental-ternaries + Use curious ternaries, with the question mark after the condition + Defaults to "false" + --html-whitespace-sensitivity + How to handle whitespaces in HTML + Defaults to "css" + --jsx-single-quote Use single quotes in JSX + Defaults to "false" + --object-wrap + How to wrap object literals + Defaults to "preserve" + --parser + Which parser to use + --print-width The line length where Prettier will try wrap + Defaults to "80" + --prose-wrap + How to wrap prose + Defaults to "preserve" + --quote-props + Change when properties in objects are quoted + Defaults to "as-needed" + --no-semi Do not print semicolons, except at the beginning of lines which may need them + Defaults to "true" + --single-attribute-per-line + Enforce single attribute per line in HTML, Vue and JSX + Defaults to "false" + --single-quote Use single quotes instead of double quotes + Defaults to "false" + --tab-width Number of spaces per indentation level + Defaults to "2" + --trailing-comma + Print trailing commas wherever possible when multi-line + Defaults to "all" + --use-tabs Indent with tabs instead of spaces + Defaults to "false" + --vue-indent-script-and-style + Indent script and style tags in Vue files + Defaults to "false" + + CONFIG OPTIONS + + --no-config Do not look for a configuration file + --config-path Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js) + --config-precedence + Define in which order config files and CLI options should be evaluated. + Defaults to "cli-override" + --no-editorconfig Don't take .editorconfig into account when parsing configuration + --no-ignore Do not look for an ignore file + --ignore-path Path to a file with patterns describing files to ignore + Multiple values are accepted + Defaults to [.gitignore, .prettierignore] + --plugin Add a plugin + Multiple plugins are accepted + Defaults to [] + --with-node-modules Process files inside the "node_modules" directory + + EDITOR OPTIONS + + --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting + Defaults to "-1" + --range-end Format code ending at a given character offset (exclusive) + The range will extend forwards to the end of the selected statement + Defaults to "Infinity" + --range-start Format code starting at a given character offset + The range will extend backwards to the start of the first line containing the selected statement + Defaults to "0" + + OTHER OPTIONS + + --help Display help for the command + --version, -v Display the version number + --no-cache Do not use the built-in caching mechanism + --cache-location Path to the cache file + --no-color Do not colorize output messages + --no-error-on-unmatched-pattern + Prevent errors when pattern is unmatched + --ignore-unknown, -u Ignore unknown files + --insert-pragma Insert @format pragma into file's first docblock comment + Defaults to "false" + --log-level + What level of logs to report + Defaults to "log" + --no-parallel Process files in parallel + Defaults to "true" + --parallel-workers Number of parallel workers to use + Defaults to "0" + --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-filepath Path to the file to pretend that stdin comes from + ", "write": [], } `; @@ -162,210 +143,71 @@ exports[`show version with --version 1`] = ` } `; -exports[`show warning with --help not-found (typo) 1`] = ` +exports[`throw error with --check + --list-different 1`] = ` { - "stderr": "[warn] Unknown flag "parserr", did you mean "parser"?", - "stdout": "--parser - - Which parser to use. - -Valid options: - - flow Flow - babel JavaScript - babel-flow Flow - babel-ts TypeScript - typescript TypeScript - acorn JavaScript - espree JavaScript - meriyah JavaScript - css CSS - less Less - scss SCSS - json JSON - json5 JSON5 - jsonc JSON with Comments - json-stringify JSON.stringify - graphql GraphQL - markdown Markdown - mdx MDX - vue Vue - yaml YAML - glimmer Ember / Handlebars - html HTML - angular Angular - lwc Lightning Web Components - mjml MJML", + "stderr": " + Incompatible options: "check" and "list-different" cannot be used together +", + "stdout": "", "write": [], } `; -exports[`throw error and show usage with something unexpected 1`] = ` +exports[`throw error with --check + --write 1`] = ` { - "stderr": "", - "stdout": "Usage: prettier [options] [file/dir/glob ...] - -By default, output is written to stdout. -Stdin is read if it is piped to Prettier and no files are given. - -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). - -w, --write Edit files in-place. (Beware!) - -Format options: - - --arrow-parens - Include parentheses around a sole arrow function parameter. - Defaults to always. - --bracket-same-line Put > of opening tags on the last line instead of on a new line. - Defaults to false. - --no-bracket-spacing Do not print spaces between brackets. - --embedded-language-formatting - Control how Prettier formats quoted code embedded in the file. - Defaults to auto. - --end-of-line - Which end of line characters to apply. - Defaults to lf. - --experimental-operator-position - Where to print operators when binary expressions wrap lines. - Defaults to end. - --no-experimental-ternaries - Default behavior of ternaries; keep question marks on the same line as the consequent. - --html-whitespace-sensitivity - How to handle whitespaces in HTML. - Defaults to css. - --jsx-single-quote Use single quotes in JSX. - Defaults to false. - --object-wrap - How to wrap object literals. - Defaults to preserve. - --parser - Which parser to use. - --print-width The line length where Prettier will try wrap. - Defaults to 80. - --prose-wrap - How to wrap prose. - Defaults to preserve. - --quote-props - Change when properties in objects are quoted. - Defaults to as-needed. - --no-semi Do not print semicolons, except at the beginning of lines which may need them. - --single-attribute-per-line - Enforce single attribute per line in HTML, Vue and JSX. - Defaults to false. - --single-quote Use single quotes instead of double quotes. - Defaults to false. - --tab-width Number of spaces per indentation level. - Defaults to 2. - --trailing-comma - Print trailing commas wherever possible when multi-line. - Defaults to all. - --use-tabs Indent with tabs instead of spaces. - Defaults to false. - --vue-indent-script-and-style - Indent script and style tags in Vue files. - Defaults to false. - -Config options: - - --config Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js). - --no-config Do not look for a configuration file. - --config-precedence - Define in which order config files and CLI options should be evaluated. - Defaults to cli-override. - --no-editorconfig Don't take .editorconfig into account when parsing configuration. - --find-config-path - Find and print the path to a configuration file for the given input file. - --ignore-path Path to a file with patterns describing files to ignore. - Multiple values are accepted. - Defaults to [.gitignore, .prettierignore]. - --plugin Add a plugin. Multiple plugins can be passed as separate \`--plugin\`s. - Defaults to []. - --with-node-modules Process files inside 'node_modules' directory. - -Editor options: - - --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting. - Defaults to -1. - --range-end Format code ending at a given character offset (exclusive). - The range will extend forwards to the end of the selected statement. - Defaults to Infinity. - --range-start Format code starting at a given character offset. - The range will extend backwards to the start of the first line containing the selected statement. - Defaults to 0. - -Other options: - - --cache Only format changed files. Cannot use with --stdin-filepath. - Defaults to false. - --cache-location Path to the cache file. - --cache-strategy - Strategy for the cache to use for detecting changed files. - --check-ignore-pragma Check whether the file's first docblock comment contains '@noprettier' or '@noformat' to determine if it should be formatted. - Defaults to false. - --no-color Do not colorize error messages. - --no-error-on-unmatched-pattern - Prevent errors when pattern is unmatched. - --file-info Extract the following info (as JSON) for a given file path. Reported fields: - * ignored (boolean) - true if file path is filtered by --ignore-path - * inferredParser (string | null) - name of parser inferred from file path - -h, --help Show CLI usage, or details about the given flag. - Example: --help write - -u, --ignore-unknown Ignore unknown files. - --insert-pragma Insert @format pragma into file's first docblock comment. - Defaults to false. - --log-level - What level of logs to report. - Defaults to log. - --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-filepath Path to the file to pretend that stdin comes from. - --support-info Print support information as JSON. - -v, --version Print Prettier version. - + "stderr": " + Incompatible options: "check" and "write" cannot be used together ", + "stdout": "", "write": [], } `; -exports[`throw error with --check + --list-different 1`] = ` +exports[`throw error with --list-different + --write 1`] = ` { - "stderr": "[error] Cannot use --check and --list-different together.", + "stderr": " + Incompatible options: "list-different" and "write" cannot be used together +", "stdout": "", "write": [], } `; -exports[`throw error with --file-info + multiple files 1`] = ` +exports[`throw error with something unexpected 1`] = ` { - "stderr": "[error] Cannot use --file-info with multiple files", + "stderr": " + Expected at least one target file/dir/glob +", "stdout": "", "write": [], } `; -exports[`throw error with --find-config-path + multiple files 1`] = ` +exports[`throw unsupported error with --file-info 1`] = ` { - "stderr": "[error] Cannot use --find-config-path with multiple files", + "stderr": " + The "--file-info" option is not currently supported, please open an issue on GitHub if you need it +", "stdout": "", "write": [], } `; -exports[`throw error with --help not-found 1`] = ` +exports[`throw unsupported error with --find-config-path 1`] = ` { - "stderr": "[error] Invalid --help value. Expected a flag, but received "not-found".", + "stderr": " + Unknown option: "find-config-path" +", "stdout": "", "write": [], } `; -exports[`throw error with --write + --debug-check 1`] = ` +exports[`throw unsupported error with --support-info 1`] = ` { - "stderr": "[error] Cannot use --write and --debug-check together.", + "stderr": " + The "--support-info" option is not currently supported, please open an issue on GitHub if you need it +", "stdout": "", "write": [], } diff --git a/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap b/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap index 0a1d40e..d0d5bff 100644 --- a/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap +++ b/test/__tests__/__snapshots__/error-on-unmatched-pattern.js.snap @@ -2,15 +2,15 @@ exports[`error on unmatched pattern 1`] = ` { - "stderr": "[error] No files matching the pattern were found: "**/*.toml".", + "stderr": "[error] No files matching the given patterns were found.", "stdout": "", "write": [], } `; -exports[`error on unmatched pattern when 2nd glob has no match 1`] = ` +exports[`error on unmatched pattern when 2nd glob has no match, by default 1`] = ` { - "stderr": "[error] No files matching the pattern were found: "**/*.toml".", + "stderr": "", "stdout": "const hello = "there"; { "hello": "there" @@ -28,7 +28,7 @@ exports[`no error on unmatched pattern 1`] = ` } `; -exports[`no error on unmatched pattern when 2nd glob has no match 1`] = ` +exports[`no error on unmatched pattern when 2nd glob has no match, with flag 1`] = ` { "stderr": "", "stdout": "const hello = "there"; diff --git a/test/__tests__/__snapshots__/ignore-emoji.js.snap b/test/__tests__/__snapshots__/ignore-emoji.js.snap index 892c0df..5fd372c 100644 --- a/test/__tests__/__snapshots__/ignore-emoji.js.snap +++ b/test/__tests__/__snapshots__/ignore-emoji.js.snap @@ -7,11 +7,3 @@ exports[`ignores file name contains emoji 1`] = ` "write": [], } `; - -exports[`stdin 1`] = ` -{ - "stderr": "", - "stdout": ".name { display: none; }", - "write": [], -} -`; diff --git a/test/__tests__/__snapshots__/ignore-folder.js.snap b/test/__tests__/__snapshots__/ignore-folder.js.snap index 930f12a..1c15942 100644 --- a/test/__tests__/__snapshots__/ignore-folder.js.snap +++ b/test/__tests__/__snapshots__/ignore-folder.js.snap @@ -1,17 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ignores files in ignored folders (stderr) 1`] = `""`; - -exports[`ignores files in ignored folders (stdout) 1`] = `"not-ignored.js"`; - -exports[`ignores files in ignored folders (write) 1`] = `[]`; - -exports[`ignores ignore files when processing stdin (stderr) 1`] = `""`; +exports[`ignores files in ignored folders 1`] = ` +{ + "stderr": "", + "stdout": "not-ignored.js", + "write": [], +} +`; -exports[`ignores ignore files when processing stdin (stdout) 1`] = ` -".name { +exports[`ignores ignore files when processing stdin 1`] = ` +{ + "stderr": "", + "stdout": ".name { display: none; -}" +}", + "write": [], +} `; - -exports[`ignores ignore files when processing stdin (write) 1`] = `[]`; diff --git a/test/__tests__/__snapshots__/ignore-relative-path.js.snap b/test/__tests__/__snapshots__/ignore-relative-path.js.snap index 484ba15..09bd26f 100644 --- a/test/__tests__/__snapshots__/ignore-relative-path.js.snap +++ b/test/__tests__/__snapshots__/ignore-relative-path.js.snap @@ -3,9 +3,9 @@ exports[`support relative paths 1`] = ` { "stderr": "", - "stdout": "shouldNotBeIgnored.js -level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss -level1-glob/shouldNotBeIgnored.js", + "stdout": "level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss +level1-glob/shouldNotBeIgnored.js +shouldNotBeIgnored.js", "write": [], } `; diff --git a/test/__tests__/__snapshots__/ignore-unknown.js.snap b/test/__tests__/__snapshots__/ignore-unknown.js.snap index 89d9bc6..72c4004 100644 --- a/test/__tests__/__snapshots__/ignore-unknown.js.snap +++ b/test/__tests__/__snapshots__/ignore-unknown.js.snap @@ -10,7 +10,7 @@ exports[`Ignored file 1`] = ` exports[`None exist file 1`] = ` { - "stderr": "[error] No files matching the pattern were found: "non-exist-file".", + "stderr": "[error] No files matching the given patterns were found.", "stdout": "", "write": [], } @@ -18,7 +18,7 @@ exports[`None exist file 1`] = ` exports[`Not matching pattern 1`] = ` { - "stderr": "[error] No files matching the pattern were found: "*.non-exist-pattern".", + "stderr": "[error] No files matching the given patterns were found.", "stdout": "", "write": [], } diff --git a/test/__tests__/__snapshots__/ignore-vcs-files.js.snap b/test/__tests__/__snapshots__/ignore-vcs-files.js.snap index b3b5cad..e9687e7 100644 --- a/test/__tests__/__snapshots__/ignore-vcs-files.js.snap +++ b/test/__tests__/__snapshots__/ignore-vcs-files.js.snap @@ -1,6 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ignores files in version control systems 1`] = ` +exports[`does not ignore files in version control systems, if manually provided 1`] = ` +{ + "stderr": "", + "stdout": ".hg/file.js +.svn/file.js +file.js", + "write": [], +} +`; + +exports[`ignores files in version control systems, if discovered 1`] = ` { "stderr": "", "stdout": "file.js", diff --git a/test/__tests__/__snapshots__/invalid-ignore.js.snap b/test/__tests__/__snapshots__/invalid-ignore.js.snap index c75f612..75c29f0 100644 --- a/test/__tests__/__snapshots__/invalid-ignore.js.snap +++ b/test/__tests__/__snapshots__/invalid-ignore.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`throw error with invalid ignore 1`] = ` +exports[`ignores .prettierignore folder 1`] = ` { - "stderr": "[error] Unable to read '.prettierignore': EISDIR: illegal operation on a directory, read", + "stderr": "", "stdout": "", "write": [], } diff --git a/test/__tests__/__snapshots__/patterns-glob.js.snap b/test/__tests__/__snapshots__/patterns-glob.js.snap index 8d3ec1a..7a53642 100644 --- a/test/__tests__/__snapshots__/patterns-glob.js.snap +++ b/test/__tests__/__snapshots__/patterns-glob.js.snap @@ -32,9 +32,9 @@ exports[`fixtures-2: Should match all js files and all supported files in the '! { "stderr": "", "stdout": "!b.js -a.js !dir.js/1.css -!dir.js/2.css", +!dir.js/2.css +a.js", "write": [], } `; @@ -47,28 +47,29 @@ exports[`fixtures-2: Should only match \`!b.js\` 1`] = ` } `; -exports[`fixtures-3: Should exclude \`.svn\` (existing) 1`] = ` +exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` 1`] = ` { "stderr": "", - "stdout": "outside.js", + "stdout": "dir/inside.js +dir/node_modules/in-node_modules.js +outside.js", "write": [], } `; -exports[`fixtures-3: Should exclude \`.svn\` (nonexisting) 1`] = ` +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (existing) 1`] = ` { "stderr": "", - "stdout": "outside.js", + "stdout": "dir/.svn/in-svn.js +outside.js", "write": [], } `; -exports[`fixtures-3: Should match \`outside.js\`, \`dir/inside.js\` and \`dir/node_modules/in-node_modules.js\` 1`] = ` +exports[`fixtures-3: Should not exclude \`.svn\` when specified explicitly (nonexisting) 1`] = ` { "stderr": "", - "stdout": "dir/inside.js -dir/node_modules/in-node_modules.js -outside.js", + "stdout": "outside.js", "write": [], } `; diff --git a/test/__tests__/__snapshots__/patterns.js.snap b/test/__tests__/__snapshots__/patterns.js.snap index 34d65b1..cd89e65 100644 --- a/test/__tests__/__snapshots__/patterns.js.snap +++ b/test/__tests__/__snapshots__/patterns.js.snap @@ -1,5 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`exits with an informative message when there are no patterns provided 1`] = ` +{ + "stderr": " + Expected at least one target file/dir/glob +", + "stdout": "", + "write": [], +} +`; + exports[`multiple patterns 1`] = ` { "stderr": "", @@ -11,22 +21,22 @@ other-directory/nested-directory/nested-directory-file.js", } `; -exports[`multiple patterns by with ignore pattern, doesn't ignore node_modules with --with-node-modules flag 1`] = ` +exports[`multiple patterns with a negated pattern 1`] = ` { "stderr": "", - "stdout": "node_modules/node-module.js + "stdout": "directory/file.js other-directory/file.js -other-directory/nested-directory/nested-directory-file.js other-regular-modules.js regular-module.js", "write": [], } `; -exports[`multiple patterns by with ignore pattern, ignores node_modules by default 1`] = ` +exports[`multiple patterns with a negated pattern, doesn't ignore node_modules with the --with-node-modules flag 1`] = ` { "stderr": "", - "stdout": "other-directory/file.js + "stdout": "node_modules/node-module.js +other-directory/file.js other-directory/nested-directory/nested-directory-file.js other-regular-modules.js regular-module.js", @@ -34,7 +44,7 @@ regular-module.js", } `; -exports[`multiple patterns by with ignore pattern, ignores node_modules by with ./**/*.js 1`] = ` +exports[`multiple patterns with a negated pattern, ignores node_modules by default 1`] = ` { "stderr": "", "stdout": "other-directory/file.js @@ -45,38 +55,18 @@ regular-module.js", } `; -exports[`multiple patterns with ignore nested directories pattern 1`] = ` +exports[`multiple patterns with an extra non-existent pattern 1`] = ` { "stderr": "", "stdout": "directory/file.js -other-directory/file.js -other-regular-modules.js -regular-module.js", - "write": [], -} -`; - -exports[`multiple patterns with non exists pattern 1`] = ` -{ - "stderr": "[error] No files matching the pattern were found: "non-existent.js".", - "stdout": "directory/file.js directory/nested-directory/nested-directory-file.js", "write": [], } `; -exports[`multiple patterns, throw error and exit with non zero code on non existing files 1`] = ` +exports[`multiple patterns, throws an error and exits with a non-zero code when there are no matches 1`] = ` { - "stderr": "[error] No files matching the pattern were found: "non-existent.js". -[error] No files matching the pattern were found: "other-non-existent.js".", - "stdout": "", - "write": [], -} -`; - -exports[`no errors on empty patterns 1`] = ` -{ - "stderr": "", + "stderr": "[error] No files matching the given patterns were found.", "stdout": "", "write": [], } diff --git a/test/__tests__/__snapshots__/plugin-options-string.js.snap b/test/__tests__/__snapshots__/plugin-options-string.js.snap index 8d7b679..9b1cc15 100644 --- a/test/__tests__/__snapshots__/plugin-options-string.js.snap +++ b/test/__tests__/__snapshots__/plugin-options-string.js.snap @@ -1,43 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`show detailed external option with \`--help foo-string\` 1`] = ` -{ - "stderr": "", - "stdout": "--foo-string - - foo description - -Default: bar", - "write": [], -} -`; - exports[`show external options with \`--help\` 1`] = ` -"Snapshot Diff: -- First value -+ Second value - -@@ -27,19 +27,21 @@ - --experimental-operator-position - Where to print operators when binary expressions wrap lines. - Defaults to end. - --no-experimental-ternaries - Default behavior of ternaries; keep question marks on the same line as the consequent. -+ --foo-string foo description -+ Defaults to bar. - --html-whitespace-sensitivity - How to handle whitespaces in HTML. - Defaults to css. - --jsx-single-quote Use single quotes in JSX. - Defaults to false. - --object-wrap - How to wrap object literals. - Defaults to preserve. -- --parser -+ --parser - Which parser to use. - --print-width The line length where Prettier will try wrap. - Defaults to 80. - --prose-wrap - How to wrap prose." +" --parser + --foo-string foo description + Defaults to "bar"" `; diff --git a/test/__tests__/__snapshots__/plugin-options.js.snap b/test/__tests__/__snapshots__/plugin-options.js.snap index dd11d78..fb9a753 100644 --- a/test/__tests__/__snapshots__/plugin-options.js.snap +++ b/test/__tests__/__snapshots__/plugin-options.js.snap @@ -1,87 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`include plugin's parsers to the values of the \`parser\` option\` 1`] = ` -{ - "stderr": "", - "stdout": "--parser - - Which parser to use. - -Valid options: - - flow Flow - babel JavaScript - babel-flow Flow - babel-ts TypeScript - typescript TypeScript - acorn JavaScript - espree JavaScript - meriyah JavaScript - css CSS - less Less - scss SCSS - json JSON - json5 JSON5 - jsonc JSON with Comments - json-stringify JSON.stringify - graphql GraphQL - markdown Markdown - mdx MDX - vue Vue - yaml YAML - glimmer Ember / Handlebars - html HTML - angular Angular - lwc Lightning Web Components - mjml MJML - foo-parser foo (plugin: ./plugin.cjs)", - "write": [], -} -`; - -exports[`show detailed external option with \`--help foo-option\` 1`] = ` -{ - "stderr": "", - "stdout": "--foo-option - - foo description - -Valid options: - - bar bar description - baz baz description - -Default: bar", - "write": [], -} -`; - exports[`show external options with \`--help\` 1`] = ` -"Snapshot Diff: -- First value -+ Second value - -@@ -27,19 +27,21 @@ - --experimental-operator-position - Where to print operators when binary expressions wrap lines. - Defaults to end. - --no-experimental-ternaries - Default behavior of ternaries; keep question marks on the same line as the consequent. -+ --foo-option foo description -+ Defaults to bar. - --html-whitespace-sensitivity - How to handle whitespaces in HTML. - Defaults to css. - --jsx-single-quote Use single quotes in JSX. - Defaults to false. - --object-wrap - How to wrap object literals. - Defaults to preserve. -- --parser -+ --parser - Which parser to use. - --print-width The line length where Prettier will try wrap. - Defaults to 80. - --prose-wrap - How to wrap prose." +" --parser + --foo-option foo description + Defaults to "bar"" `; diff --git a/test/__tests__/__snapshots__/print-code.js.snap b/test/__tests__/__snapshots__/print-code.js.snap index 132bca1..521f565 100644 --- a/test/__tests__/__snapshots__/print-code.js.snap +++ b/test/__tests__/__snapshots__/print-code.js.snap @@ -2,17 +2,12 @@ exports[`Line breaking after filepath with errors 1`] = ` { - "stdout": "ignored.js -[[called readline.clearLine(process.stdout)]] -foo( -)", + "stdout": "foo();", } `; exports[`Line breaking after filepath with errors 2`] = ` { - "stdout": "not-ignored.js -[[called readline.clearLine(process.stdout)]] -foo();", + "stdout": "foo();", } `; diff --git a/test/__tests__/__snapshots__/syntax-error.js.snap b/test/__tests__/__snapshots__/syntax-error.js.snap index 6296e8f..b3c3302 100644 --- a/test/__tests__/__snapshots__/syntax-error.js.snap +++ b/test/__tests__/__snapshots__/syntax-error.js.snap @@ -2,7 +2,7 @@ exports[`exits with non-zero code when input has a syntax error 1`] = ` { - "stderr": "[error] stdin: SyntaxError: Missing semicolon. (1:2) + "stderr": "[error] SyntaxError: Missing semicolon. (1:2) [error] > 1 | a.2 [error] | ^", "stdout": "", diff --git a/test/__tests__/__snapshots__/with-node-modules.js.snap b/test/__tests__/__snapshots__/with-node-modules.js.snap index 5e8abe0..ca57eb0 100644 --- a/test/__tests__/__snapshots__/with-node-modules.js.snap +++ b/test/__tests__/__snapshots__/with-node-modules.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`doesn't ignore node_modules with --with-node-modules flag 1`] = ` +exports[`does not ignore node_modules for manual file list 1`] = ` { "stderr": "", "stdout": "nested/node_modules/node-module.js @@ -11,12 +11,12 @@ regular-module.js", } `; -exports[`doesn't ignore node_modules with --with-node-modules flag for file list 1`] = ` +exports[`doesn't ignore node_modules with --with-node-modules flag 1`] = ` { "stderr": "", - "stdout": "node_modules/node-module.js + "stdout": "nested/node_modules/node-module.js +node_modules/node-module.js not_node_modules/file.js -nested/node_modules/node-module.js regular-module.js", "write": [], } @@ -31,15 +31,6 @@ regular-module.js", } `; -exports[`ignores node_modules by default for file list 1`] = ` -{ - "stderr": "", - "stdout": "not_node_modules/file.js -regular-module.js", - "write": [], -} -`; - exports[`ignores node_modules by with ./**/*.js 1`] = ` { "stderr": "", diff --git a/test/__tests__/__snapshots__/with-parser-inference.js.snap b/test/__tests__/__snapshots__/with-parser-inference.js.snap index 5a32a72..14a07ef 100644 --- a/test/__tests__/__snapshots__/with-parser-inference.js.snap +++ b/test/__tests__/__snapshots__/with-parser-inference.js.snap @@ -1,5 +1,53 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`infers parser from filename (.prettierrc) 1`] = ` +{ + "stdout": "{}", +} +`; + +exports[`infers parser from filename (.stylelintrc YAML) 1`] = ` +{ + "stdout": "extends: """, +} +`; + +exports[`infers parser from filename (.stylelintrc) 1`] = ` +{ + "stdout": "{}", +} +`; + +exports[`infers parser from filename (jakefile) 1`] = ` +{ + "stdout": "let foo = (x = 1) => x;", +} +`; + +exports[`infers parser from filename (lintstagedrc YAML) 1`] = ` +{ + "stdout": ""*": + - your-cmd", +} +`; + +exports[`infers parser from filename (lintstagedrc) 1`] = ` +{ + "stdout": "{ "*": "your-cmd" }", +} +`; + +exports[`infers parser from filename (swcrc) 1`] = ` +{ + "stdout": "{ + "jsc": { + // Requires v1.2.50 or upper and requires target to be es2016 or upper. + "keepClassNames": false + } +}", +} +`; + exports[`infers postcss parser 1`] = ` { "stderr": "", diff --git a/test/__tests__/__snapshots__/write.js.snap b/test/__tests__/__snapshots__/write.js.snap deleted file mode 100644 index ddeed12..0000000 --- a/test/__tests__/__snapshots__/write.js.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`do not write file with --write + formatted file 1`] = ` -{ - "stderr": "", - "stdout": "formatted.js 0ms (unchanged)", -} -`; - -exports[`do not write file with --write + invalid file 1`] = ` -{ - "stderr": "[error] invalid.js: SyntaxError: Unexpected token (1:17) -[error] > 1 | this is invalid! -[error] | ^", - "stdout": "", -} -`; - -exports[`write file with --write + unformatted file 1`] = ` -{ - "stderr": "", - "stdout": "unformatted.js 0ms", - "write": [ - { - "content": "var x = 1; -", - "filename": "unformatted.js", - }, - ], -} -`; - -exports[`write file with -w + unformatted file 1`] = ` -{ - "stderr": "", - "stdout": "unformatted.js 0ms", - "write": [ - { - "content": "var x = 1; -", - "filename": "unformatted.js", - }, - ], -} -`;