How to Set Up ESLint and Prettier in 10 Minutes

Two tools handle most of the style arguments in a JavaScript project, and they do different jobs. ESLint catches bugs and bad patterns in your code. Prettier formats the code so it looks the same no matter who wrote it. Together they remove a whole class of review comments, and learning how to set up ESLint and Prettier takes less time than most developers expect. This guide walks through a plain setup for a JavaScript project, from install to editor integration, in about ten minutes.

What each tool does

ESLint reads your code and flags problems. It warns you about unused variables, missing returns, and patterns that tend to cause bugs. You can extend it with shared rule sets, so a team agrees on the rules once instead of arguing about them in every pull request. Prettier does not care about bugs. It only cares about formatting: indentation, quote style, line length, trailing commas. It rewrites your files to match the style you chose, and it does it the same way every time. Because the two tools cover different ground, you run both. The trick is to stop ESLint from arguing about formatting, since that is Prettier’s job.

How to set up ESLint and Prettier step by step

Start in the root of your project, next to package.json. If the project has no package.json yet, run npm init and accept the defaults. Then install both tools as development dependencies. ESLint needs a config file, and Prettier needs one too. The two config files are short, and you can adjust them later once you know which rules fit your team. The point of the first pass is a working setup, not a perfect one.

Install the packages

Run this in your terminal:

npm install --save-dev eslint prettier eslint-config-prettier

The third package, eslint-config-prettier, turns off every ESLint rule that could clash with Prettier. Without it, the two tools can fight over the same lines, and you will see warnings that disappear when you format. If you work in TypeScript, add the TypeScript parser and plugin as well, and the same pattern holds: ESLint checks the code, Prettier formats it. The install takes under a minute on most connections. Once it finishes, the two config files are the only remaining setup.

Create the config files

Create a file called eslint.config.js in the project root. A flat config for a plain JavaScript project can start with the recommended rule set and a couple of sensible defaults. Keep it short at first. You can add rules for your framework later, when you know which ones your team wants. Next, create a file called .prettierrc with your Prettier formatting choices: two spaces for indentation, single quotes, semicolons, and a print width of 80 or 100 characters. There is no single right answer here. What matters is that the whole project uses one style, and that the choice is written down in a file everyone shares. If you are migrating a JavaScript project to TypeScript, keep the same Prettier settings and extend the ESLint config with the TypeScript rules instead of starting over.

Make them work together without fighting

The most common setup mistake is skipping eslint-config-prettier and then wondering why ESLint complains about formatting. The config file should extend the Prettier config last, so its rule overrides win. Run ESLint on a file after the setup and check that no formatting warnings appear. If a warning mentions quotes, indentation, or trailing commas, it is a formatting rule that should be off, and the Prettier config is not loaded in the right place. Fix that before you move on. A clean run at this stage saves a lot of confusion later, because every later warning will be a real code problem, not a style argument.

Wire up editor integration

Command line checks are useful, but the setup only sticks when your editor runs the tools for you. In VS Code, install the ESLint and Prettier extensions. Then add workspace settings that format on save with Prettier and fix ESLint problems on save. The two settings to set are the default formatter and the code action that runs on save. Test it: open a file, write a badly indented line with double quotes, and save. The file should snap into your chosen style, and any ESLint problem that can be fixed automatically should be fixed too. Other editors have the same idea under different names. The goal is the same: feedback while you type, not a surprise at review time.

Add scripts to package.json

Add two scripts so the whole team runs the same checks. One is the command to lint JavaScript code across the project, the other checks formatting without changing files. A typical pair looks like this:

"lint": "eslint ."

"format:check": "prettier --check ."

Add a third script that formats the whole project when you want it, "format": "prettier --write .", and use it before a big commit. Run these scripts in your CI pipeline too, so a pull request fails when the code breaks the rules. That is the step that turns a local habit into a team rule. When linting runs in CI, nobody has to remember to run it, and nobody has to ask for style fixes in a review. If you are setting up tests alongside the linter, a guide on unit testing with Jest pairs well with this setup, since tests and linting catch different kinds of mistakes.

Fix common setup mistakes

Four problems show up again and again. First, ESLint reports errors in files you never meant to check, such as the build output or node_modules. Add an ignores list to the ESLint config and a .prettierignore file with the same folders. Second, formatting changes appear in every file after the first run. That usually means the project was formatted with different settings before, or not formatted at all. Run the format script once, commit the result as its own commit, and the noise goes away. Third, the editor formats with its own defaults instead of your config. Check that the project has a Prettier config file in the root and that the editor is set to use the workspace version of Prettier. Fourth, two developers get different results from the same setup. That points to different installed versions, so check the lockfile into version control and make sure everyone installs from it.

Keep the setup working as the project grows

A linter setup is not a one-time task. When you add a framework, add its ESLint plugin and rules. When the team agrees on a new rule, add it to the config and fix the existing code in the same change, so the rule is enforced from day one. When a rule keeps getting disabled with inline comments, treat that as a signal. Either the rule does not fit the project and should change, or the team needs to talk about why it keeps getting skipped. Review the config every few months and remove rules nobody can explain. A short config that the team understands beats a long one that everyone ignores. If you want to compare the test runners that sit next to this setup, the comparison of Jest, Vitest, and Mocha covers the trade-offs, and when a test fails in ways the linter cannot explain, debugging in Chrome DevTools is the next place to look.

That is the whole setup: install two tools, write two short config files, turn off the clashing rules, wire up the editor, and add the scripts. Ten minutes of setup buys you cleaner diffs, faster reviews, and fewer style debates for the rest of the project.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.