Automating Code Quality: The Modern Stack with ESLint, Prettier, and Husky
A step-by-step setup for automatic code quality in a JavaScript or TypeScript project. Prettier handles formatting, ESLint with flat config and typescript-eslint catches bugs, eslint-config-prettier stops the two from fighting, VS Code fixes files on save, and Husky with lint-staged checks only the staged files before each commit. Every step was run with ESLint 10 and Prettier 3.

Arguing about quotes and indentation in code review wastes everyone's time, and a linter you forget to run catches nothing. This guide is for JavaScript and TypeScript developers who want formatting and basic bug checks to happen on their own. You'll set up Prettier for formatting, ESLint for code problems, make your editor fix files on save, and add a Git hook that checks every commit. Each step was run in a fresh project.
This is part 25 of the Frontend & JavaScript Fundamentals series. It follows debugging with Chrome DevTools: DevTools helps you find bugs, and this setup stops some of them reaching a commit.
Key takeaways
- Prettier formats, ESLint finds code problems, and
eslint-config-prettierturns off the ESLint rules that would clash with Prettier. - ESLint 10 only reads flat config (
eslint.config.mjs);.eslintrcfiles no longer work. - Husky runs lint-staged before each commit, and lint-staged checks only the files you staged.
Linting and formatting are different jobs
Prettier is a code formatter. It decides how code looks: line breaks, indentation, quotes and commas. It doesn't care whether a variable is used.
ESLint is a linter. It checks what code does and reports problems such as unused variables or == comparisons that coerce types. Some ESLint rules also cover style, and that overlap is where the two tools can fight.
The plan is simple: Prettier owns style, ESLint owns code quality, and Git hooks make sure both run.
| Tool | What it does | Trade-off | When it runs |
|---|---|---|---|
| Prettier | Rewrites code into one consistent format | Few options by design | On save and before commit |
| ESLint | Reports problems and fixes some | Needs rule choices and config | In the editor and before commit |
| eslint-config-prettier | Turns off ESLint rules that clash with Prettier | One more config entry | Always, last in the ESLint config |
| Husky + lint-staged | Runs the tools on staged files before a commit | Can be skipped with git commit --no-verify |
On every commit |
Step 1: Install and configure Prettier
The Prettier docs recommend pinning an exact version, so everyone on the project formats the same way.
npm install --save-dev --save-exact prettier
Checked against prettier@3.9.10, eslint@10.13.0, @eslint/js@10.0.1, typescript-eslint@8.72.1, typescript@6.0.3, globals@17.13.0, eslint-config-prettier@10.1.8, husky@9.1.7 and lint-staged@17.6.0, on Node.js 22, 2026-10-29.
Create .prettierrc in the project root. This config spells out every option so you can see what's set.
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"printWidth": 80,
"bracketSpacing": true,
"endOfLine": "lf"
}
According to the Prettier options page, most of these are already the defaults in Prettier 3. Only two change anything:
singleQuote: trueuses single quotes; the default is double.trailingComma: "es5"adds trailing commas where ES5 allows them, in arrays and objects. The default changed to"all"in Prettier 3.0, which also adds them to function parameters. Trailing commas keep diffs small: adding an item changes one line, not two.
endOfLine: "lf" has been the default since Prettier 2.0. It avoids line-ending churn when people commit from both Windows and macOS or Linux. If you're happy with the defaults, an empty {} works too.
Add a .prettierignore so build output is never formatted:
# Ignore artifacts:
build
coverage
dist
Step 2: Set up ESLint with flat config
ESLint now reads a single file, eslint.config.js or eslint.config.mjs, that exports an array of config objects. This is called flat config. The ESLint v10 migration guide says the old .eslintrc format is no longer supported, so older tutorials that use it won't work with current ESLint. The guide also lists the Node.js versions ESLint 10 supports: 20.19 or later in the 20 line, 22.13 or later, and 24 or later.
For a TypeScript project, install ESLint with the packages from the typescript-eslint getting started guide, plus globals for Node.js globals:
npm install --save-dev eslint @eslint/js typescript typescript-eslint globals
For a new project, npm init @eslint/config@latest asks a few questions and writes a starter config. The ESLint getting started guide covers it.
Step 3: Stop ESLint and Prettier from fighting
If an ESLint rule wants one style and Prettier writes another, every save flips the code back and forth. The eslint-config-prettier README says the package turns off all rules that are unnecessary or might conflict with Prettier. It only turns rules off, so put it after the configs it should override.
npm install --save-dev eslint-config-prettier
Now create eslint.config.mjs in the project root:
import js from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default defineConfig([
globalIgnores(['build/', 'coverage/', 'dist/']),
{
files: ['**/*.{js,mjs,cjs,ts}'],
languageOptions: { globals: globals.node },
extends: [js.configs.recommended, tseslint.configs.recommended],
rules: {
'@typescript-eslint/no-unused-vars': 'warn',
'no-console': 'warn',
'prefer-const': 'error',
eqeqeq: ['error', 'always'],
},
},
eslintConfigPrettier, // last: turns off rules that conflict with Prettier
]);
Here's what each part does:
defineConfigandglobalIgnorescome fromeslint/config. The ESLint docs recommendglobalIgnores()so it's clear the ignores apply to the whole project.filesandextendssit in the same object. The recommended JavaScript and TypeScript rules apply only to the listed file types, and therulesbelow override them.eqeqeqreports==and!=, which coerce types before comparing.prefer-constreportsletvariables that are never reassigned, andeslint --fixcan change them toconst.eslintConfigPrettiercomes from the/flatentry point, which the README recommends for flat config, and it goes last.
Run npx eslint . to lint the whole project. To check that no remaining rule conflicts with Prettier, the README offers a helper: npx eslint-config-prettier src/index.ts, pointed at any file in your project.
Fixed in this version
The earlier config turned on the core no-unused-vars rule for TypeScript. typescript-eslint says you must turn that rule off, because it can report wrong errors on TypeScript code. In a test run it flagged the event parameter in a type such as (event: string) => void, and reported real unused variables twice. Use @typescript-eslint/no-unused-vars instead, as above.
// Avoid in TypeScript projects: false reports on type parameters, duplicates
const avoid = { rules: { 'no-unused-vars': 'warn' } };
// Better: the TypeScript-aware version (tseslint.configs.recommended turns it on)
const better = { rules: { '@typescript-eslint/no-unused-vars': 'warn' } };
Step 4: Fix files when you save in VS Code
Running commands by hand is easy to forget. With the Prettier and ESLint extensions installed, a .vscode/settings.json file in the project makes every save format the file and apply ESLint's automatic fixes. Commit it, so everyone who clones the repo gets the same behavior.
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
}
The VS Code ESLint extension README documents source.fixAll.eslint as fixing all auto-fixable ESLint problems on save. Older guides also add an eslint.validate list. You don't need it for these file types: the README lists JavaScript, TypeScript and their React variants among the languages the extension checks by default.
Step 5: Check every commit with Husky and lint-staged
Editor settings help, but they don't cover someone using another editor or rushing a hotfix. A Git pre-commit hook does.
Husky manages Git hooks from your repository. lint-staged runs commands only on files staged for the commit, so the check stays fast on a big project. The Prettier install docs use the same two packages:
npm install --save-dev husky lint-staged
npx husky init
The Husky docs say husky init creates a .husky/pre-commit file and adds a prepare script to package.json. The new hook runs npm test. Replace the contents of .husky/pre-commit with one line:
npx lint-staged
Then tell lint-staged what to run. Add this to package.json:
"lint-staged": {
"*.{js,mjs,cjs,ts}": ["eslint --fix", "prettier --write"],
"*.{json,css,md}": "prettier --write"
}
Three details from the lint-staged README matter here:
- A pattern without a slash, like
*.ts, matches files in any folder. - Commands in an array run in order, and the next one runs only if the previous one passed. The Prettier docs say to run ESLint before Prettier, not after, which is the order above.
- Changes the tools make are added to the commit for you. If a task fails, lint-staged undoes the tools' changes and the commit stops.
The ESLint glob matches the files pattern in eslint.config.mjs. If you add .jsx or .tsx files, add them in both places, along with a React ESLint plugin.
Node.js version
The engines field in lint-staged@17's package.json asks for Node.js 22.22.1 or later. On an older runtime, check that field before you install, or pin an earlier major version of lint-staged.
What a commit looks like now
- You edit
src/auth.tsand leave in an==comparison and some messy formatting. - You run
git add .andgit commit -m "feat: auth". - Husky starts the pre-commit hook, which runs lint-staged on the staged files only.
eslint --fixfixes what it can, such aslettoconst, then reports the==as an error. The commit stops, and you see the file and line. lint-staged rolls back theconstfix too; it's applied again on the next commit.- You change
==to===and commit again. ESLint passes, Prettier reformats the file, and the formatted version is what gets committed.
In the test run behind this guide, the first commit was blocked by eqeqeq, and the second went through with Prettier's formatting applied.
What to add next
The Git docs note that a pre-commit hook can be skipped with git commit --no-verify, so run the same checks in CI as well. npx eslint . and the Prettier docs' npx prettier . --check both exit with an error when something is wrong, which fails the build. Next in the series, Webpack and Babel covers the build step these checks run in front of.
Frequently asked questions
Do I still need eslint-config-prettier with ESLint 10?
The README still recommends it, because shared configs and plugins can turn on rules that clash with Prettier. It costs one line at the end of your config. The npx eslint-config-prettier <file> helper tells you whether any conflicts remain.
Can I keep my .eslintrc file?
Not with ESLint 10. The migration guide says the old format is no longer supported. Move to eslint.config.mjs; the ESLint docs link a configuration migration guide. If you can't migrate yet, stay on ESLint 9 for now.
Why run ESLint before Prettier in lint-staged?
eslint --fix can change code, and Prettier should format the final result. The Prettier docs say to run ESLint before Prettier, not after. lint-staged runs the commands in the order you list them.
Is Husky required, or can I use plain Git hooks?
Git hooks work without Husky. But the Git docs say hooks live in .git/hooks by default, which isn't part of the repository, so teammates don't get them. Husky keeps the hooks in a committed .husky folder, and the prepare script it adds sets them up when someone runs npm install. That makes the check the same for everyone.
Should Prettier run in CI too?
Yes, as a rule of thumb, because hooks can be skipped. Run npx prettier . --check and npx eslint . in your pipeline. Both fail the job when the code doesn't match.
Sources
Verified against the sources below on October 29, 2026. Products and docs change often: check the linked sources if something looks different.
- ESLint docs: Getting Started
- ESLint docs: Configuration Files
- ESLint docs: Migrate to v10.x
- typescript-eslint: Getting Started
- typescript-eslint: no-unused-vars
- Prettier docs: Install
- Prettier docs: Options
- eslint-config-prettier README
- lint-staged package.json (engines)
- Husky docs: Get started
- lint-staged README
- Git docs: githooks
- VS Code ESLint extension README
All 30 parts in this series
- Part 01Overcoming the Daunting Start: A Strategic Roadmap for New Frontend Developers
- Part 02Beyond the Tags: Mastering HTML Architecture for Product-Based Roles
- Part 03From Selectors to BEM: CSS Concepts You Must Know for Professional Projects
- Part 04Mastering the Primitives: A Builder's Guide to JavaScript Data Types and Functions
- Part 05Demystifying Scope and Closure: Key Concepts for Writing Robust JavaScript
- Part 06Beyond Frameworks: Practical DOM Manipulation Techniques for High-Performance UIs
- Part 07From Prototypes to ES6 Classes: Understanding JavaScript's Object-Oriented Nature
- Part 08Architecting Scalable JavaScript: OOP Principles & Design Patterns
- Part 09Mastering the Metal: Essential Web APIs & Browser Internals for Frontend Engineers
- Part 10Understanding the JavaScript Runtime: Event Loop, Call Stack, and Task Queue Explained
- Part 11Mastering Asynchronous Operations with JavaScript Promises: A Builder's Guide
- Part 12Modern Async Patterns: Making Asynchronous Code Readable with Async/Await and Generators
- Part 13Inside the V8 Engine: A Deep Dive into JavaScript Execution
- Part 14Demystifying CORS, HTTP, and Security: A Builder’s Guide
- Part 15REST vs. GraphQL: A Frontend Engineer’s Reality Check
- Part 16Secure Frontend Auth: The Definitive Guide to JWTs, Cookies, and Storage Strategies
- Part 17Why TypeScript Matters: Adding Type Safety to Your JavaScript Projects
- Part 18Getting Started with React: Deconstructing JSX and Component Architecture
- Part 19React Architecture: Mastering State and Props in Class vs. Functional Components
- Part 20Mastering React Hooks: From useState to Building a Production-Ready Custom Hook
- Part 21React State Management: Context API vs. Redux & Building a Theme Switcher
- Part 22React Architecture: Advanced Navigation and Data Flow Patterns
- Part 23Automated Testing in React: Unit Testing with Jest and React Testing Library
- Part 24Mastering Chrome DevTools: Debugging Techniques That Save Hours of Development Time
- Part 25Automating Code Quality: The Modern Stack with ESLint, Prettier, and Husky
- Part 26Demystifying the Build Pipeline: A Deep Dive into Webpack and Babel Configuration
- Part 27Improving Performance with Server-Side Rendering: Concepts and Implementation
- Part 28From Development to Production: A Builder's Guide to Frontend Deployment Strategies
- Part 29Introduction to Micro Frontends: Building Scalable Architectures
- Part 30The Frontend Architecture: From Junior Developer to Tech Lead
AI Automation Engineer & Salesforce Developer
Salesforce developer since June 2018. I build AI agents, n8n workflows and Salesforce integrations, and write up what holds up in real use.



Comments
Loading comments...