| | |

Prettier 30 🎨 Cheatsheet

⏱️ Estimated read: 5 min | |

Prettier 3.x is ESM-first, async, and plugin-driven. The config file resolution searches upward from the file being formatted, and the first config found wins. The CLI flags map to the API options, and the plugins are the extension surface for languages and sorting.


The CLI Commands

CommandPurpose
prettier .Format to stdout (no write)
prettier . --writeFormat in place
prettier . --checkCheck formatting, exit 1 if unformatted
prettier . --list-differentList unformatted files
prettier . --debug-checkVerify correctness preservation
prettier . --find-config-path <file>Locate the config for a file

The --check and --list-different flags are the CI gates. The --write flag is the local correction step.


The Core Options

OptionDefaultCLI
printWidth80--print-width <int>
tabWidth2--tab-width <int>
useTabsfalse--use-tabs
semitrue--no-semi
singleQuotefalse--single-quote
quoteProps"as-needed"--quote-props <as-needed|consistent|preserve>
jsxSingleQuotefalse--jsx-single-quote
trailingComma"all"--trailing-comma <all|es5|none>
bracketSpacingtrue--no-bracket-spacing
arrowParens"always"--arrow-parens <always|avoid>
endOfLine"lf"--end-of-line <lf|crlf|cr|auto>

The trailingComma default changed to "all" in 3.0. The arrowParens default is "always".


The Parser Option

Prettier infers the parser from the file extension. The --parser flag overrides the inference for stdin or unknown extensions.

ParserLanguage
babelJavaScript (default)
babel-tsTypeScript via Babel
typescriptTypeScript
flowFlow
espreeJavaScript (ESLint parser)
css / scss / lessStylesheets
json / json5 / jsoncJSON variants
markdown / mdxMarkdown
html / vue / angularHTML variants
yamlYAML
graphqlGraphQL

The --stdin-filepath flag infers the parser from a filename when reading from stdin.


The Config File Resolution

The config is resolved from the file being formatted, searching upward. The first config found wins. The supported forms, in order of precedence:

  1. "prettier" key in package.json
  2. .prettierrc (JSON or YAML)
  3. .prettierrc.json, .prettierrc.yml, .prettierrc.yaml, .prettierrc.json5
  4. .prettierrc.js, prettier.config.js, .prettierrc.ts, prettier.config.ts (ESM or CJS)
  5. .prettierrc.mjs, prettier.config.mjs, .prettierrc.mts, prettier.config.mts
  6. .prettierrc.cjs, prettier.config.cjs, .prettierrc.cts, prettier.config.cts
  7. .prettierrc.toml

The --config <path> flag bypasses the search and points to a specific file.


The Overrides Pattern

The overrides array applies options to matching files. The files pattern is relative to the config file’s directory, not the cwd.

{
  "semi": false,
  "overrides": [
    { "files": "*.test.js", "options": { "semi": true } },
    { "files": ["*.html", "legacy/**/*.js"], "options": { "tabWidth": 4 } }
  ]
}

A pattern without a / matches the filename alone at any depth. The excludeFiles property excludes files from an override.


The Ignore Mechanism

Prettier 3.x honors .gitignore by default. The .prettierignore file adds project-specific exclusions.

MechanismScope
.gitignoreHonored by default in 3.x
.prettierignoreProject-specific exclusions
--ignore-path <path>Custom ignore file
// prettier-ignoreNext AST node in a file

The --ignore-path flag accepts multiple files. The .prettierignore uses gitignore syntax.


The Shared Config Pattern

A shareable config is a module that exports a config object. The consuming package references it by name.

// package.json
{ "prettier": "@company/prettier-config" }

The package.json reference does not support extending. A package that needs overrides imports the config and spreads it.

// prettier.config.mjs
import sharedConfig from "@company/prettier-config";
export default { ...sharedConfig, printWidth: 100 };

The spread is shallow. A package that changes the plugins array must spread the shared array and append the new plugin.


The Plugin Surface

A Prettier 3 plugin exports languages, parsers, and printers.

ExportPurpose
languagesFile extensions and parser names
parsersparse, locStart, locEnd
printersprint (returns a Doc), comment hooks, insertPragma

The print function returns a Doc, not a string. The Doc is built with prettier.doc.builders (group, line, indent, concat). Async parsers are supported. The custom parser API was removed in 3.0.


The Common Plugins

PluginPurpose
prettier-plugin-tailwindcssSort Tailwind classes
@ianvs/prettier-plugin-sort-importsSort imports (safer fork)
@trivago/prettier-plugin-sort-importsSort imports (original)
prettier-plugin-organize-importsSort and remove unused (broken with TS 7)

The Tailwind plugin needs tailwindStylesheet (v4) or tailwindConfig (v3). The import-sorting plugins use importOrder with special words (<BUILTIN_MODULES>, <THIRD_PARTY_MODULES>, <TYPES>).


The 3.0 Breaking Changes

ChangeDetail
ESM sourceCJS bridge still works for library use
format() asyncReturns Promise<string>
Custom parser removedPlugin API is the replacement
trailingComma default"all" (was "es5")
Flow in babel parserRemoved; use flow parser or @flow pragma
Markdown CJK spacingNo space between CJK and Latin

The API Calls

FunctionReturnsNotes
prettier.format(source, options)Promise<string>Async in 3.x
prettier.check(source, options)Promise<boolean>Async in 3.x
prettier.resolveConfig(filePath)Promise<object | null>Searches upward
prettier.getFileInfo(filePath)Promise<{ ignored, inferredParser }>The formattable gate

The format and check functions require await. The resolveConfig result is spread into the options. The filepath option infers the parser.


The One-Line Summary

ESM source. Async API. Plugin-driven. Config searches upward. trailingComma is "all".

Prettier 3.x is a formatter that migrated to ESM, removed the synchronous API, and replaced the custom parser with the plugin contract. The config is resolved from the file being formatted, and the first config found wins. The plugins are the language and sorting extensions. The CLI is the gate, and the API is the integration.


Summary

AreaKey takeaway
CLI--write, --check, --list-different
OptionstrailingComma: "all", printWidth: 80, semi: true
ParserInferred from extension; --parser overrides
ConfigSearches upward; first found wins
Overridesfiles relative to config file
Ignore.gitignore honored; .prettierignore adds
Shared configModule export, reference by name
Pluginslanguages, parsers, printers
3.0 changesESM, async, custom parser removed

Remember: Prettier 3.x is ESM-first and async. The config searches upward, and the first config found wins. The trailingComma default is "all". The plugins are the language and sorting extensions, and the print function returns a Doc. The CLI is the gate, and the API is the integration. The custom parser is gone; the plugin is the replacement.

Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!