Prettier with ESLint Integration
What you'll learn: How to prevent Prettier and ESLint from fighting over code style by disabling conflicting ESLint rules.
The Problem: Two Tools, Same Territory
When you run both Prettier and ESLint together, you might notice them disagreeing about formatting. ESLint might flag an error saying "Expected single quotes" while Prettier automatically formats with double quotes. This creates a frustrating loop where fixing one tool's complaint breaks the other's rules.
Think of it like having two editors reviewing your document—one wants Oxford commas, the other forbids them. You need to tell one editor to stay out of punctuation decisions entirely.
The Solution: eslint-config-prettier
The eslint-config-prettier package solves this by disabling all ESLint rules that conflict with Prettier. It basically tells ESLint: "Prettier handles formatting—you focus on code quality and errors."
Setup Steps
- Install the package:
npm install --save-dev eslint-config-prettier
- Add to your
.eslintrcextends array (must be last):
{
"extends": [
"eslint:recommended",
"prettier"
]
}
The order matters—"prettier" must come last to override any formatting rules from other configs.
What It Does
This config turns off rules like:
quotes(Prettier controls quote style)semi(Prettier controls semicolons)indent(Prettier handles indentation)max-len(Prettier wraps lines)
ESLint still catches logical errors, unused variables, and code quality issues—it just stops complaining about formatting that Prettier manages.
Key Takeaway: Use eslint-config-prettier to let Prettier own all formatting decisions while ESLint focuses on code correctness, eliminating conflicts between the two tools.