Prettier 30 🎨 Cheatsheet
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
| Command | Purpose |
|---|---|
prettier . | Format to stdout (no write) |
prettier . --write | Format in place |
prettier . --check | Check formatting, exit 1 if unformatted |
prettier . --list-different | List unformatted files |
prettier . --debug-check | Verify 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
| Option | Default | CLI |
|---|---|---|
printWidth | 80 | --print-width <int> |
tabWidth | 2 | --tab-width <int> |
useTabs | false | --use-tabs |
semi | true | --no-semi |
singleQuote | false | --single-quote |
quoteProps | "as-needed" | --quote-props <as-needed|consistent|preserve> |
jsxSingleQuote | false | --jsx-single-quote |
trailingComma | "all" | --trailing-comma <all|es5|none> |
bracketSpacing | true | --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.
| Parser | Language |
|---|---|
babel | JavaScript (default) |
babel-ts | TypeScript via Babel |
typescript | TypeScript |
flow | Flow |
espree | JavaScript (ESLint parser) |
css / scss / less | Stylesheets |
json / json5 / jsonc | JSON variants |
markdown / mdx | Markdown |
html / vue / angular | HTML variants |
yaml | YAML |
graphql | GraphQL |
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:
"prettier"key inpackage.json.prettierrc(JSON or YAML).prettierrc.json,.prettierrc.yml,.prettierrc.yaml,.prettierrc.json5.prettierrc.js,prettier.config.js,.prettierrc.ts,prettier.config.ts(ESM or CJS).prettierrc.mjs,prettier.config.mjs,.prettierrc.mts,prettier.config.mts.prettierrc.cjs,prettier.config.cjs,.prettierrc.cts,prettier.config.cts.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.
| Mechanism | Scope |
|---|---|
.gitignore | Honored by default in 3.x |
.prettierignore | Project-specific exclusions |
--ignore-path <path> | Custom ignore file |
// prettier-ignore | Next 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.
| Export | Purpose |
|---|---|
languages | File extensions and parser names |
parsers | parse, locStart, locEnd |
printers | print (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
| Plugin | Purpose |
|---|---|
prettier-plugin-tailwindcss | Sort Tailwind classes |
@ianvs/prettier-plugin-sort-imports | Sort imports (safer fork) |
@trivago/prettier-plugin-sort-imports | Sort imports (original) |
prettier-plugin-organize-imports | Sort 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
| Change | Detail |
|---|---|
| ESM source | CJS bridge still works for library use |
format() async | Returns Promise<string> |
| Custom parser removed | Plugin API is the replacement |
trailingComma default | "all" (was "es5") |
Flow in babel parser | Removed; use flow parser or @flow pragma |
| Markdown CJK spacing | No space between CJK and Latin |
The API Calls
| Function | Returns | Notes |
|---|---|---|
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
| Area | Key takeaway |
|---|---|
| CLI | --write, --check, --list-different |
| Options | trailingComma: "all", printWidth: 80, semi: true |
| Parser | Inferred from extension; --parser overrides |
| Config | Searches upward; first found wins |
| Overrides | files relative to config file |
| Ignore | .gitignore honored; .prettierignore adds |
| Shared config | Module export, reference by name |
| Plugins | languages, parsers, printers |
| 3.0 changes | ESM, 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.
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!