ESLint and Prettier: Differences and How They Work Together

eslint vs prettier

Wondering about eslint vs prettier? You don’t have to pick one. Prettier formats your code, while ESLint catches bugs and bad patterns, and the two work well side by side once formatting rules are kept out of ESLint.

This guide is part of our look at the best developer tools, and it focuses on one very common pairing.

Item Value
How Prettier works Reprints the whole program from scratch
Rule categories in linters 2 categories: formatting rules and code-quality rules
typescript-eslint advice on formatting Use Prettier, dprint, or an equivalent instead of ESLint
eslint-config-prettier Disables formatting rules in your ESLint configuration
eslint-plugin-prettier Loads and runs Prettier inside ESLint, which can be slow
ESLint stylistic rules Frozen, per ESLint’s 2020 rule-policy post

These figures and recommendations come from Prettier’s comparison docs and typescript-eslint’s formatting guide. They can change, so check the source before you rely on them.

What each tool actually does

Prettier is a formatter, and it is not a rule-based tool. According to Prettier’s own comparison page, it has no individual formatting rules that you can enable or disable, and it reprints your whole program from scratch instead.

ESLint is a linter. In Josh Goldberg’s description, ESLint parses your code into a format rules understand, passes the code to those rules, and reports whatever they flag. You configure the rules individually, and plugins and shareable configs extend what is available.

So the answer to eslint vs prettier is a division of labour. Prettier’s docs put it plainly: use Prettier for formatting and linters for catching bugs.

Formatting rules versus code-quality rules

Prettier’s docs sort linter rules into two categories, and the split explains why the tools overlap so little:

  • Formatting rules, such as max-len, no-mixed-spaces-and-tabs, keyword-spacing and comma-style.
  • Code-quality rules, such as no-unused-vars, no-extra-bind, no-implicit-globals and prefer-promise-reject-errors.

Prettier removes the need for the whole formatting category, because it reprints the program consistently and leaves no room for a formatting mistake. It does nothing for code-quality rules, which the docs call the most important ones a linter provides because they are likely to catch real bugs.

eslint vs prettier Screen closeup
Multicolored lines fill a dark computer screen photographed with shallow depth of field.

Why not format with ESLint?

The typescript-eslint project is direct: it recommends against using ESLint for formatting and suggests Prettier, dprint, or an equivalent instead. You can read the reasoning in its formatting guide.

Speed is part of it. Formatters typically run very quickly because they only change whitespace, while linters often take seconds or more because they apply many logical rules to code.

Linters also run each rule in isolation, which causes problems when rules are used to format:

  • Any two lint rules can’t share config, so one rule’s fixer might introduce a violation of another rule’s fixer, such as using the wrong indentation character.
  • Rule fixers can conflict by applying to the same code range, which forces the linter to run an additional cycle.
  • Formatting with a linter is less consistent and handles edge cases worse than a purpose-built formatter.

ESLint itself has moved on. According to the typescript-eslint guide, the ESLint team’s 2020 Changes to Rule Policies post froze stylistic rules, and a January 2024 edit to one of Goldberg’s posts notes that ESLint core deprecated formatting rules.

If you strongly prefer not to use a dedicated formatter, the eslint-stylistic project provides an ESLint plugin with formatting and stylistic rules that can serve as your formatter. The trade-off with Prettier runs the other way: formatters are much more opinionated than lint rules, though you can ignore code, including inline with // prettier-ignore comments.

How to run ESLint and Prettier together

A clean setup keeps each tool in its own lane. Work through these steps:

  1. Let Prettier own formatting, and configure it separately from ESLint.
  2. Start ESLint from recommended presets. According to typescript-eslint, neither it nor ESLint core enable any formatting-related rules in any recommended presets.
  3. Check whether any config you extend turns formatting rules on. If one does, add eslint-config-prettier at the end of your config so it disables them.
  4. If you are unsure you still need it, remove it and run npx eslint-config-prettier some/file.js, which points out any conflicting rules.

Position matters. Goldberg explains that eslint-config-prettier could be placed last in a project’s ESLint config to turn off any formatting rules enabled by previous plugins.

Once both tools run cleanly, you can wire them into pull requests. Our roundup of the best code review tools is a place to compare options for running checks there.

Do you need eslint-config-prettier or eslint-plugin-prettier?

The names are easy to mix up, but eslint-config-prettier is not the same as eslint-plugin-prettier. The typescript-eslint guide explains that the config only disables rules from core and other plugins, while the plugin loads and runs Prettier inside ESLint.

In a January 2024 post, Goldberg argues that if you don’t use a legacy shareable config that enables formatting rules, you probably don’t need the config. Adding it at the end of the list does nothing if nothing enabled formatting rules to begin with.

He is more critical of the plugin, and names two big problems with running Prettier inside an ESLint rule:

  • Behavioral: it joins Prettier’s reports with ESLint’s, which can confuse developers who aren’t familiar with the tools.
  • Performance: formatting is blocked on all linting, which is often much slower than formatting.

The typescript-eslint guide takes a softer view. Running Prettier inside ESLint can be slow, but because the plugin doesn’t re-implement Prettier’s logic in ESLint, the caveats about using linters for formatting don’t apply to it, as the guide notes.

Where formatting and style blur

Some rules sit between the two tools. In his post on the topic, Goldberg suggests that formatters should never change code behavior, apart from the odd case of stringifying functions.

Two edge cases show why the line is fuzzy:

  • Curly braces: Prettier does not have an option to enforce curly brackets, because formatters generally avoid changes to how code is represented by tooling. Goldberg published prettier-plugin-curly to add consistent brace style to Prettier.
  • Import order: order can affect runtime because code files sometimes trigger side effects when they are run. He doesn’t recommend a Prettier plugin for sorting, and suggests eslint-plugin-perfectionist to apply sorting at the lint level instead.

If you also write Python, the flake8 vs pylint comparison covers a related linter choice.

Frequently asked questions

Can ESLint replace Prettier?

Show answer

It can, but typescript-eslint recommends against it and suggests a dedicated formatter. If you do want to stay inside ESLint, the eslint-stylistic plugin provides formatting and stylistic rules, as described in the typescript-eslint guide.

Can Prettier replace ESLint?

Show answer

No. Prettier removes the need for formatting rules, but its docs say it does nothing to help with code-quality rules such as no-unused-vars.

Are eslint-config-prettier and eslint-plugin-prettier the same thing?

Show answer

No. The config only turns rules off, while the plugin runs Prettier as a rule inside ESLint, as the Goldberg post describes.

Do I need tslint-config-prettier for TypeScript?

Show answer

No. In his May 2023 FAQ, Goldberg explains that those packages work with TSLint, which is deprecated, so you don’t need them for plain TypeScript.