Sub topic 11
Making ESLint and Prettier Work Together
This chapter assumes you already have ESLint running with an eslint.config.js flat config and Prettier installed with a .prettierrc file, as set up in earlier chapters. You should also know how flat config entries merge and how rule severities work.
Why the Two Tools Collide
ESLint was around long before Prettier, and it shipped many rules about code style: indent, quotes, semi, max-len, comma-dangle, and dozens more. Those rules are still available. The core versions are deprecated, and plugins such as @stylistic/eslint-plugin carry them forward. Shared configs you install from npm often turn them on as well.
Prettier makes the same decisions in its own way. If ESLint's quotes rule demands double quotes and your .prettierrc sets "singleQuote": true, the tools fight each other:
- Prettier rewrites
"hello"to'hello'. - ESLint reports
'hello'as an error. eslint --fixrewrites it back to"hello".- The next format-on-save flips it again.
Even when both tools happen to agree on a style, running two formatters is wasted work. They also produce duplicate warnings, and someone has to keep two configs in sync. The fix is to give each tool one job. ESLint finds code-quality problems such as unused variables, unsafe equality, and unreachable code. Prettier owns every decision about layout.
eslint-config-prettier: Turning Off the Overlap
eslint-config-prettier is a shared config that contains only "off" settings. It disables every ESLint rule that is unnecessary or that conflicts with Prettier. That covers core rules, @stylistic rules, and formatting rules from common plugins such as React and typescript-eslint. It adds no rules of its own, so it never reports anything.
Install it alongside Prettier:
npm install --save-dev prettier eslint-config-prettierThen add it to your flat config as the last entry:
// eslint.config.js
import js from "@eslint/js";
import globals from "globals";
import eslintConfigPrettier from "eslint-config-prettier";
export default [
js.configs.recommended,
{
files: ["**/*.js"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: { ...globals.node },
},
rules: {
"no-unused-vars": "warn",
eqeqeq: ["error", "always"],
},
},
// Keep this last so it turns off rules that conflict with Prettier
eslintConfigPrettier,
];Why Order Matters
In a flat config, ESLint merges every matching entry from top to bottom, and a later entry overrides an earlier one when both set the same rule. eslint-config-prettier works only by overriding, so it has to come after everything that might turn a formatting rule on.
Here is a common mistake. A teammate adds a style rule after the Prettier entry:
// eslint.config.js (wrong order)
import js from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
export default [
js.configs.recommended,
eslintConfigPrettier,
{
rules: {
quotes: ["error", "double"], // re-enabled after Prettier's entry: conflict returns
},
},
];Because the quotes entry comes later, it wins and the fight starts again. Either delete style rules like this one or move them above eslintConfigPrettier, where they will be switched off anyway.
Checking for Conflicts
The package includes a command-line helper. It resolves your config for a given file and lists any enabled rules that conflict with Prettier:
npx eslint-config-prettier src/index.jsIf it reports nothing, you are clean. Run it again after adding a new plugin or shared config, because those are the usual source of new conflicts. The helper checks the config that applies to the file you name. If you use different files globs for different parts of the project, check one file from each.
A Few Rules Need Special Care
Some rules turned off by eslint-config-prettier are not formatting rules in the strict sense. They can still clash with Prettier output in edge cases. Examples are curly with certain options, no-unexpected-multiline, max-len, and no-mixed-operators. You can re-enable some of them deliberately if you understand the trade-off. The package's README lists the exact conditions. The safe default is to leave them off.
The Alternative: eslint-plugin-prettier
A second package, eslint-plugin-prettier, takes a different approach. It runs Prettier inside ESLint and reports every formatting difference as an ESLint problem through a prettier/prettier rule. Its recommended config also includes eslint-config-prettier.
| Approach | How formatting is applied | Strengths | Weaknesses |
|---|---|---|---|
| `eslint-config-prettier` + run Prettier separately | Prettier runs as its own command or on save | Fast, simple, clear split of responsibility, recommended by Prettier | Two commands to run |
| `eslint-plugin-prettier` | Prettier runs inside ESLint as a rule | One command, formatting shows up as lint errors | Slower linting, editors fill with red squiggles for whitespace, some autofixes can interact badly |
The Prettier team advises against the plugin approach for most projects. Formatting issues are not bugs. Marking every misplaced space as an error buries the real problems, and running Prettier through ESLint's rule machinery is slower than running it directly. This tutorial uses the first approach. Later chapters show how npm scripts, lint-staged, and CI run the two tools side by side.
Running Both Tools in the Right Order
When you fix files automatically, run ESLint first and Prettier second:
npx eslint . --fix && npx prettier . --writeESLint's autofixes, such as rewriting == to === or removing unused code, can leave the layout slightly off. Running Prettier last means the final output is always in Prettier's style. With eslint-config-prettier in place, ESLint makes no formatting edits, so the order affects only the final layout. Neither tool undoes the other's work.
For checks without changes, as in CI, the order does not matter. Both commands only report:
npx eslint . && npx prettier . --checkEdge Cases Worth Knowing
- TypeScript and framework plugins.
eslint-config-prettieralso disables formatting rules from typescript-eslint, React, Vue, and other plugins. You still need one copy of it, placed last. - Per-directory entries. If a later entry targets
files: ["tests/**"]and enables a style rule, it overrides the Prettier entry for those files only. The CLI helper finds this if you point it at a test file. - Prettier version changes. Upgrading Prettier can change its output. That causes a one-time reformat but no ESLint conflicts, because ESLint no longer has an opinion about formatting.
eslint-disablecomments for style rules. After the integration, comments such as// eslint-disable-next-line quotesare dead weight. ESLint can report them if you enablelinterOptions.reportUnusedDisableDirectives.
Exercise
Your config array is [js.configs.recommended, eslintConfigPrettier, someStyleGuideConfig], where someStyleGuideConfig enables "indent" and "semi". Prettier keeps reformatting files that ESLint then flags. What is wrong, and how do you fix it?
Show answer
someStyleGuideConfig comes after eslintConfigPrettier, so its "indent" and "semi" settings override the "off" values and the conflict returns. Move eslintConfigPrettier to the end of the array: [js.configs.recommended, someStyleGuideConfig, eslintConfigPrettier]. Then confirm with npx eslint-config-prettier on a source file.
Exercise
A teammate proposes switching to eslint-plugin-prettier so that "npm run lint" also catches formatting. Give two reasons to keep eslint-config-prettier with a separate Prettier check instead.
Show answer
Running Prettier inside ESLint makes linting slower. It also reports harmless whitespace differences as lint errors, which buries real code-quality problems in editors and output. A separate "prettier --check" step keeps formatting checks fast and clearly separate. The Prettier team itself recommends that approach.