Skip to content

prettier

prettier documentation

prettier - GitHub

Configuration in Mega-Linter

Variable Description Default value
JSON_PRETTIER_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
JSON_PRETTIER_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
JSON_PRETTIER_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
JSON_PRETTIER_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".json"]
JSON_PRETTIER_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
JSON_PRETTIER_CONFIG_FILE prettier configuration file name
Use LINTER_DEFAULT to let the linter find it
.prettierrc.json
JSON_PRETTIER_RULES_PATH Path where to find linter configuration file Workspace folder, then Mega-Linter default rules
JSON_PRETTIER_DISABLE_ERRORS Run linter but consider errors as warnings true
JSON_PRETTIER_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

IDE Integration

Use prettier in your favorite IDE to catch errors before Mega-Linter !

IDE Extension Name Install
Atom prettier-atom Visit Web Site
Atom atom-mprettier Visit Web Site
Atom atom-miniprettier Visit Web Site
Emacs prettier-emacs Visit Web Site
Emacs prettier.el Visit Web Site
Emacs apheleia Visit Web Site
IDEA native support Visit Web Site
Sublime Text JsPrettier Visit Web Site
vim vim-prettier Visit Web Site
visual_studio JavaScriptPrettier Visit Web Site
Visual Studio Code prettier-vscode Install in VsCode

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 91 Docker Image Size (tag) Docker Pulls
ci_light Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML 13 Docker Image Size (tag) Docker Pulls
dart Optimized for DART based projects 39 Docker Image Size (tag) Docker Pulls
documentation Mega-Linter for documentation projects 38 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 44 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 40 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 39 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 47 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 42 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 47 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 39 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 39 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 41 Docker Image Size (tag) Docker Pulls
scala Optimized for SCALA based projects 39 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 39 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 43 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .json

Example calls

prettier --check myfile.json
prettier --config .prettierrc.json --check myfile.json
prettier --config .prettierrc.json --write myfile.json

Help content

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 <always|avoid>
                           Include parentheses around a sole arrow function parameter.
                           Defaults to always.
  --no-bracket-spacing     Do not print spaces between brackets.
  --embedded-language-formatting <auto|off>
                           Control how Prettier formats quoted code embedded in the file.
                           Defaults to auto.
  --end-of-line <lf|crlf|cr|auto>
                           Which end of line characters to apply.
                           Defaults to lf.
  --html-whitespace-sensitivity <css|strict|ignore>
                           How to handle whitespaces in HTML.
                           Defaults to css.
  --jsx-bracket-same-line  Put > on the last line instead of at a new line.
                           Defaults to false.
  --jsx-single-quote       Use single quotes in JSX.
                           Defaults to false.
  --parser <flow|babel|babel-flow|babel-ts|typescript|espree|meriyah|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc>
                           Which parser to use.
  --print-width <int>      The line length where Prettier will try wrap.
                           Defaults to 80.
  --prose-wrap <always|never|preserve>
                           How to wrap prose.
                           Defaults to preserve.
  --quote-props <as-needed|consistent|preserve>
                           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-quote           Use single quotes instead of double quotes.
                           Defaults to false.
  --tab-width <int>        Number of spaces per indentation level.
                           Defaults to 2.
  --trailing-comma <es5|none|all>
                           Print trailing commas wherever possible when multi-line.
                           Defaults to es5.
  --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>          Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).
  --no-config              Do not look for a configuration file.
  --config-precedence <cli-override|file-override|prefer-file>
                           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 <path>
                           Find and print the path to a configuration file for the given input file.
  --ignore-path <path>     Path to a file with patterns describing files to ignore.
                           Defaults to .prettierignore.
  --plugin <path>          Add a plugin. Multiple plugins can be passed as separate `--plugin`s.
                           Defaults to [].
  --plugin-search-dir <path>
                           Custom directory that contains prettier plugins in node_modules subdirectory.
                           Overrides default behavior when plugins are searched relatively to the location of Prettier.
                           Multiple values are accepted.
                           Defaults to [].
  --with-node-modules      Process files inside 'node_modules' directory.

Editor options:

  --cursor-offset <int>    Print (to stderr) where a cursor at the given position would move to after formatting.
                           This option cannot be used with --range-start and --range-end.
                           Defaults to -1.
  --range-end <int>        Format code ending at a given character offset (exclusive).
                           The range will extend forwards to the end of the selected statement.
                           This option cannot be used with --cursor-offset.
                           Defaults to Infinity.
  --range-start <int>      Format code starting at a given character offset.
                           The range will extend backwards to the start of the first line containing the selected statement.
                           This option cannot be used with --cursor-offset.
                           Defaults to 0.

Other options:

  --no-color               Do not colorize error messages.
  --no-error-on-unmatched-pattern
                           Prevent errors when pattern is unmatched.
  --file-info <path>       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 <flag>        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.
  --loglevel <silent|error|warn|log|debug>
                           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>  Path to the file to pretend that stdin comes from.
  --support-info           Print support information as JSON.
  -v, --version            Print Prettier version.


Installation on mega-linter Docker image