skip to content

In an ESLint flat config, what does `eslint-config-prettier` do, and where must it go in the exported array?

level: middleimportance: must knowfreq 24%

answer

  1. a config, not a plugin
  2. only switches rules off
  3. the /flat entry point
  4. after the configs it overrides
  5. a CLI helper finds leftovers

basics

~10 s

eslint-config-prettier turns off every ESLint rule that is unnecessary with Prettier or would fight it. In flat config you import eslint-config-prettier/flat and place it after the configs it must override, because later objects win.

solid answer

~40 s

`eslint-config-prettier` is a shareable config whose only job is to set formatting-related rules to off: core rules such as `indent`, `semi` and `quotes`, and the matching rules of plugins like `@stylistic`, React and Vue. It enables nothing, so it is used with other configs. In `eslint.config.js` you import it from `eslint-config-prettier/flat` (which adds a `name` for the config inspector) and put it **after** the presets it must override, since in flat config a later object wins for the same rule. Anything you enable after it comes back, so either keep your own rules before it or run its CLI helper, `npx eslint-config-prettier src/index.ts`, which reports conflicting rules left in the resolved config and exits 2 when it finds any. Prettier then runs as its own command.

code

javascript · 16 lines
javascript
import js from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier/flat";

export default defineConfig([
  {
    files: ["**/*.{js,ts,tsx}"],
    extends: [js.configs.recommended, tseslint.configs.recommended],
  },
  eslintConfigPrettier,
  {
    // a special rule re-enabled with an option that cannot fight Prettier
    rules: { curly: ["error", "all"] },
  },
]);

go deeper

for a junior

Recall that eslint-config-prettier only switches ESLint's formatting rules off, so Prettier and ESLint stop disagreeing about layout.

for a middle

Explain the /flat import, why it must come after the presets in the array, and what happens to a rule you enable after it.

for a senior

Find the leftovers: a rule re-enabled later, a plugin under a custom prefix, a special rule with a conflicting option, using the CLI helper on several files.

for a principal

Set the team convention: presets, then the Prettier config, then only rules the helper approves, so the split stays enforceable as configs grow.

## What the package is Prettier's docs on integrating with linters say: use Prettier for formatting and linters for code quality, and "turn off rules that conflict or are unnecessary with Prettier" using **`eslint-config-prettier`**. Its README states the contract in one line: it "turns off all rules that are unnecessary or might conflict with Prettier", and it "_only_ turns rules _off_, so it only makes sense using it together with some other config." It covers: - **core rules** such as `indent`, `semi`, `quotes`, `comma-dangle`, `max-len`, `object-curly-spacing`; - rules from the plugins it knows under their official names, among them `@stylistic`, `@babel`, and the React, Vue and Unicorn plugins. (typescript-eslint 8 ships no formatting rules at all; they moved to ESLint Stylistic.) It is a **config**, not a plugin: it adds no rules and does not run Prettier. ## Wiring it into flat config ```js import js from "@eslint/js"; import { defineConfig } from "eslint/config"; import tseslint from "typescript-eslint"; import eslintConfigPrettier from "eslint-config-prettier/flat"; export default defineConfig([ { files: ["**/*.{js,ts,tsx}"], extends: [js.configs.recommended, tseslint.configs.recommended], }, eslintConfigPrettier, ]); ``` Two details matter: 1. **The `/flat` entry point.** The package's `flat` export is the same rule set with a `name` property, so the config inspector can label it. 2. **Order.** When several objects in the array configure the same rule for a file, the later one wins. Placing `eslintConfigPrettier` after the presets lets its `"off"` overwrite whatever they enabled. ## What it cannot do | Situation | Result | |---|---| | A preset before it enables `indent` | turned off | | Your own object **after** it sets `indent: "error"` | `indent` is back on | | A plugin registered under your own name, e.g. `style/indent` | not turned off | | A special rule like `curly` you re-enable with safe options | allowed, on purpose | - **Re-enabled rules come back.** The README's own example shows `indent: "error"` in an object after the Prettier config: ESLint applies it, and the formatter and the linter fight again. - **Plugin names are yours in flat config.** It disables `@stylistic/indent`; if ESLint Stylistic is registered as `style`, the rule is `style/indent`, which it "cannot know". The advice: keep the official plugin names. - **Special rules** such as `curly`, `max-len`, `quotes` and `no-mixed-operators` are switched off by default but can be enabled with care. `curly` conflicts only with its `"multi-line"` or `"multi-or-nest"` options; `["error", "all"]` is safe after it. ## The CLI helper The package ships a checker: ```bash npx eslint-config-prettier src/index.ts ``` It resolves the ESLint config for that file and reports rules that conflict with Prettier or need special care. Its exit codes differ from Prettier's own: - `0` - no problems found; - `1` - unexpected error; - `2` - conflicting rules found. Because different files can match different config objects, pass several representative files, for example `npx eslint-config-prettier src/index.ts docs/build.mjs`. The README's suggestion is to put your own rules after the Prettier config and let the helper tell you which ones to delete, rather than hiding them behind a later `"off"`. ## Where ESLint's own formatting rules stand The core rules this package turns off are on their way out of ESLint anyway: `indent`, `quotes`, `semi`, `max-len` and their peers are deprecated since ESLint 8.53.0 and kept only until 11.0.0, with **ESLint Stylistic** (`@stylistic/eslint-plugin`) maintaining them. A config that pulls in `@stylistic` rules still needs `eslint-config-prettier` after them if Prettier formats the code, because those rules make the same layout decisions Prettier does. The package covers `@stylistic/indent` and its siblings under that official prefix. ## A quick verification routine 1. Run `npx eslint-config-prettier` on one file of each kind the config treats differently, such as a TypeScript component, a plain script and a test file. 2. Remove each rule it reports, or, for a special rule, switch to the options its README marks as safe. 3. Keep `prettier --check` as a separate CI step; the config switches rules off but never checks layout itself. ## Putting it together On a coworking-space portal whose old config still enables `indent`, `quotes` and `max-len`, the clean setup is: presets first, `eslintConfigPrettier` after them, the three rules deleted from the team's own object (the helper flags them), and Prettier run on its own with `prettier --check` in CI. ESLint keeps catching bugs; Prettier owns layout.

  • ESLint Stylistic is registered as `plugins: { style: stylistic }` and `style/indent` is on. Why does it still fight Prettier?
    eslint-config-prettier switches off `@stylistic/indent`, the rule's official name. In flat config the namespace is whatever key you register, so the rule is `style/indent`, which the package cannot know about; its CLI helper cannot see it either. Register the plugin under its official name, `@stylistic`.
  • Why does eslint-config-prettier leave `curly` usable?
    `curly` is a special rule: off by default, but compatible with Prettier unless you use its `"multi-line"` or `"multi-or-nest"` options, which Prettier's line breaking can violate. Setting `curly: ["error", "all"]` after the Prettier config is safe.
  • Does eslint-config-prettier make ESLint format code?
    No. It only turns rules off. Formatting still comes from running Prettier itself, on save or with `prettier --write`, and CI verifies it with `prettier --check`.

  • eslint-config-prettier runs Prettier inside ESLint
  • It works wherever it sits in the config array
  • A rule enabled after it stays off
  • It disables plugin rules whatever namespace you register
  • It turns off correctness rules like no-unused-vars too