prettier
Prettier is the industry-standard opinionated code formatter that brings consistency to YAML files by enforcing a unified style across projects. It eliminates formatting debates by automatically reformatting code according to its proven formatting principles.
Key Features:
- Opinionated Formatting: Zero-configuration approach with sensible defaults that work well for most projects
- Consistent Output: Deterministic formatting ensures identical results regardless of environment or developer
- YAML Optimization: Specialized handling of YAML syntax including proper indentation, spacing, and structure
- Multi-Language Support: Part of a comprehensive formatting ecosystem covering 20+ languages
- Parse Safety: Validates that formatted code maintains semantic equivalence to the original
- Configuration Flexibility: Supports project-specific settings through .prettierrc files when customization is needed
- Fast Performance: High-speed formatting suitable for large YAML files
- Team Standardization: Eliminates style discussions and ensures consistent formatting across team members
prettier documentation
- Version in MegaLinter: 3.9.6
- Visit Official Web Site
- See How to configure prettier rules
- See How to disable prettier rules in files
- See Index of problems detected by prettier
Configuration in MegaLinter
- Enable prettier by adding
YAML_PRETTIERin ENABLE_LINTERS variable - Disable prettier by adding
YAML_PRETTIERin DISABLE_LINTERS variable
- Enable autofixes by adding
YAML_PRETTIERin APPLY_FIXES variable
| Variable | Description | Default value |
|---|---|---|
| YAML_PRETTIER_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
| YAML_PRETTIER_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
| YAML_PRETTIER_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib)⚠️ Not available with YAML_PRETTIER_CLI_LINT_MODE = project |
Exclude no file |
| YAML_PRETTIER_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples)⚠️ Not available with YAML_PRETTIER_CLI_LINT_MODE = project |
Exclude no file |
| YAML_PRETTIER_CLI_LINT_MODE | Override default CLI lint mode - file: Calls the linter for each file- list_of_files: Call the linter with the list of files as argument- project: Call the linter from the root of the project |
list_of_files |
| YAML_PRETTIER_FORWARD_EXCLUDED_DIRECTORIES | In project CLI lint mode, forward excluded directories (EXCLUDED_DIRECTORIES + ADDITIONAL_EXCLUDED_DIRECTORIES) to the linter through its native exclusion arguments or generated ignore/config files | true |
| YAML_PRETTIER_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".yml", ".yaml"] |
| YAML_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 |
| YAML_PRETTIER_PRE_COMMANDS | List of bash commands to run before the linter | None |
| YAML_PRETTIER_POST_COMMANDS | List of bash commands to run after the linter | None |
| YAML_PRETTIER_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling YAML_PRETTIER and its pre/post commands | None |
| YAML_PRETTIER_CONFIG_FILE | prettier configuration file name Use LINTER_DEFAULT to let the linter find it |
.prettierrc.json |
| YAML_PRETTIER_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
| YAML_PRETTIER_DISABLE_ERRORS | Run linter but consider errors as warnings | true |
| YAML_PRETTIER_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
| YAML_PRETTIER_TIMEOUT_SECONDS | Maximum duration in seconds of the linter run, after which the linter process and its child processes are killed and reported as an error (exit code 124). Overrides LINTER_TIMEOUT_SECONDS. 0 disables the timeout | 300 |
| YAML_PRETTIER_CLI_EXECUTABLE | Override CLI executable | ['prettier'] |
IDE Integration
Use prettier in your favorite IDE to catch errors before MegaLinter !
| IDE | Extension Name | Install | |
|---|---|---|---|
| Emacs | prettier-emacs | Visit Web Site | |
| Emacs | prettier.el | Visit Web Site | |
| Emacs | apheleia | Visit Web Site | |
| IDEA | Prettier | ||
| Sublime Text | JsPrettier | Visit Web Site | |
| vim | vim-prettier | Visit Web Site | |
| visual_studio | JavaScriptPrettier | Visit Web Site | |
| Visual Studio Code | prettier-vscode | ![]() |
MegaLinter Flavors
This linter is available in the following flavors
| Flavor | Description | Embedded linters | Info | |
|---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 132 | |
| c_cpp | Optimized for pure C/C++ projects | 60 | ||
| ci_light | Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML | 23 | ||
| cupcake | MegaLinter for the most commonly used languages | 98 | ||
| documentation | MegaLinter for documentation projects | 53 | ||
| dotnet | Optimized for C, C++, C# or VB based projects | 67 | ||
| dotnetweb | Optimized for C, C++, C# or VB based projects with JS/TS | 83 | ||
| formatters | Contains only formatters | 19 | ||
| go | Optimized for GO based projects | 55 | ||
| java | Optimized for JAVA based projects | 58 | ||
| javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 70 | ||
| php | Optimized for PHP based projects | 58 | ||
| python | Optimized for PYTHON based projects | 70 | ||
| ruby | Optimized for RUBY based projects | 54 | ||
| rust | Optimized for RUST based projects | 54 | ||
| salesforce | Optimized for Salesforce based projects | 58 | ||
| swift | Optimized for SWIFT based projects | 54 | ||
| terraform | Optimized for TERRAFORM based projects | 56 |
Behind the scenes
How are identified applicable files
- File extensions:
.yml,.yaml
How the linting is performed
prettier is called once on the whole project directory (project CLI lint mode)
- filtering can not be done using MegaLinter configuration variables,it must be done using prettier configuration or ignore file (if existing)
VALIDATE_ALL_CODEBASE: falsedoesn't make prettier analyze only updated files
Example calls
prettier --check myfile.yml
prettier --config .prettierrc.json --check myfile.yml
prettier --config .prettierrc.json --write myfile.yml
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.
--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 <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.
--experimental-operator-position <start|end>
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 <css|strict|ignore>
How to handle whitespaces in HTML.
Defaults to css.
--jsx-single-quote Use single quotes in JSX.
Defaults to false.
--object-wrap <preserve|collapse>
How to wrap object literals.
Defaults to preserve.
--parser <flow|babel|babel-flow|babel-ts|typescript|acorn|espree|meriyah|css|less|scss|json|json5|jsonc|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc|mjml>
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-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 <int> Number of spaces per indentation level.
Defaults to 2.
--trailing-comma <all|es5|none>
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> 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.
Multiple values are accepted.
Defaults to [.gitignore, .prettierignore].
--plugin <path> 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 <int> Print (to stderr) where a cursor at the given position would move to after formatting.
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.
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.
Defaults to 0.
Other options:
--cache Only format changed files. Cannot use with --stdin-filepath.
Defaults to false.
--cache-location <path> Path to the cache file.
--cache-strategy <metadata|content>
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 <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.
--log-level <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
- Dockerfile commands :
# Parent descriptor install # renovate: datasource=npm depName=typescript ARG NPM_TYPESCRIPT_VERSION=6.0.3 # Linter install # renovate: datasource=npm depName=prettier ARG NPM_PRETTIER_VERSION=3.9.6
- NPM packages (node.js):
Known errors and resolutions
When this linter fails for a known non-lint reason (remote service unavailable, malformed config, missing credentials, etc.), MegaLinter detects the pattern below in the linter output and surfaces the matching guidance.
YAML_PRETTIER_ERROR_PLUGIN_NOT_FOUND
Detection pattern (regex):
(Cannot find (package|module) '[^']+' imported from|Directory import '[^']+' is not supported resolving ES modules)
Resolution guidance:
Prettier could not load a plugin declared in the `plugins` array of your `.prettierrc.*` (e.g. `prettier-plugin-toml`, `prettier-plugin-sh`, `@prettier/plugin-xml`).
Prettier v3 loads plugins with a native ESM `import()` resolved from its current working directory, which MegaLinter sets to the workspace. ESM ignores `NODE_PATH`, so plugins installed in MegaLinter's bundled npm root (`/node-deps/node_modules`) are invisible to Prettier, unlike for ESLint or stylelint.
Resolution: install the plugins in the workspace with a pre-command. `cwd: workspace` is required: with the default `cwd: root`, MegaLinter redirects `npm install` to `/node-deps`, where Prettier will not find them.
YAML_PRETTIER_PRE_COMMANDS:
- command: npm install --no-save prettier-plugin-toml prettier-plugin-sh
cwd: workspace
continue_if_failed: false
If the plugins are already listed in your `package.json`, run `npm ci` (or `npm install`) with the same `cwd: workspace` instead.
Keep plain package names in the `plugins` array of `.prettierrc.*`, so the very same config keeps working when you run Prettier locally without MegaLinter. Do not replace them with absolute `/node-deps/...` paths: those resolve only inside the MegaLinter image.
Also check that each package name matches the published npm package exactly (e.g. `@prettier/plugin-xml`, not `prettier-plugin-xml`).

