Prettier overrides: Per-File Style Rules
Prettier overrides let one config apply different options to different files by glob.
When Markdown wants different wrapping than code, or a legacy folder needs tabs, overrides express that in a single config without separate files.
What it does
The "overrides" key holds an array of objects, each with a "files" glob (and optional "excludeFiles") plus an "options" block. Prettier applies the options to files matching that glob, with later overrides taking precedence. You can also force a parser for non-standard extensions this way.
Common usage
// .prettierrc.json
{
"semi": true,
"overrides": [
{ "files": "*.md", "options": { "proseWrap": "always", "printWidth": 80 } },
{ "files": "legacy/**/*.js", "options": { "tabWidth": 4 } },
{ "files": ".babelrc", "options": { "parser": "json" } }
]
}Options
| Key | What it does |
|---|---|
| files | Glob (or array of globs) the override applies to |
| excludeFiles | Glob to subtract from the files match |
| options | Prettier options to apply to matched files |
| options.parser | Force a parser for files Prettier cannot infer |
In CI
Overrides keep one source of truth, which is exactly what you want so editors and CI agree. Be careful with overlapping globs: the last matching override wins, so order matters and a broad later rule can silently undo an earlier specific one.
Common errors in CI
"[error] Invalid configuration ... overrides[0].files is required" means an override is missing its files key. If an override seems ignored, the glob likely does not match the path as Prettier resolves it, or a later override overrides it. A forced parser that does not exist prints "Couldn't resolve parser ...".