Tooling & Build

Linting & Formatting

ESLint catches bugs and enforces coding standards. Prettier automatically formats your code to a consistent style. Together they save hours of code review discussions and prevent entire classes of bugs from ever shipping.

What are ESLint and Prettier?

ESLint is a linter that finds bugs and risky patterns in your code, such as unused variables, missing awaits and wrong hook usage. Prettier is a formatter that rewrites your code in one consistent style automatically. Use both: Prettier for how code looks, ESLint for what code does. Run them in your editor on save and in CI.

npm install -D eslint prettier
npx eslint .            # report problems
npx prettier . --write  # format everything

// .vscode/settings.json
{ "editor.formatOnSave": true }

ESLint — Code Quality

Catches bugs, anti-patterns, and bad practices

no-unused-vars — unused variables
no-undef — undefined references
eqeqeq — == vs ===
prefer-const — let that could be const
no-var — block-scoped let/const
no-duplicate-imports
react-hooks/exhaustive-deps — missing deps
@typescript-eslint rules — TS-specific

Prettier — Code Style

Enforces consistent visual formatting

Indentation: 2 or 4 spaces / tabs
Semicolons: on or off
Quotes: single or double
Trailing commas: es5 / all / none
Print width: max line length
Arrow function parens: always / avoid
Bracket spacing: { x } vs {x}
End of line: lf / crlf / auto

Common Pitfalls

Running ESLint and Prettier separately without coordinating them — they fight over formatting rules (e.g. indent)
Install eslint-config-prettier and put it LAST in your ESLint config to disable conflicting rules
Disabling ESLint for entire files or large sections with eslint-disable — accumulates tech debt
Disable only specific rules on specific lines: // eslint-disable-next-line no-console
Not running lint/format checks in CI — formatting 'mistakes' reach main branch
Add 'prettier --check' and 'eslint' as CI steps that fail the build on violations
Linting all of node_modules or generated files — extremely slow
Add .eslintignore and .prettierignore for node_modules, dist, .next, build, *.min.js

Interactive Demo

Code Editor

<div class="cols">
<pre>// before: what ESLint flags
var total = 0
function add(items) {
  for (var i = 0; i < items.length; i++) {
    total = total + items[i].price
  }
  let unused = 1                 // no-unused-vars
  if (total == "10") {}          // eqeqeq
}</pre>
<pre>// after: ESLint fixed + Prettier formatted
function add(items) {
  return items.reduce((sum, item) => sum + item.price, 0);
}</pre>
</div>
<pre>npx eslint . --fix
npx prettier . --write</pre>

Preview

Linting and Formatting: summary

Key points

  • Disable ESLint's style rules (with eslint-config-prettier) so the two tools don't fight.
  • Pre-commit hooks (husky with lint-staged) catch issues before they reach the repository.
  • Treat lint errors as bugs to fix, not noise to silence.

Frequently asked questions

›Do I need both ESLint and Prettier?

They do different jobs. Prettier ends formatting debates; ESLint catches real bugs. Most professional projects use both.