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 variablesno-undef — undefined referenceseqeqeq — == vs ===prefer-const — let that could be constno-var — block-scoped let/constno-duplicate-importsreact-hooks/exhaustive-deps — missing deps@typescript-eslint rules — TS-specificPrettier — Code Style
Enforces consistent visual formatting
Common Pitfalls
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.