Stop Arguing About Code Style — Set Up Prettier, ESLint & Husky Once

I’ve worked on a few frontend projects where code reviews turned into style debates—tabs vs spaces, semicolons, quote styles… you name it. It slows…

۱ دقیقه خوندن
Cover illustration for “Stop Arguing About Code Style — Set Up Prettier, ESLint & Husky Once”
توی این نوشته

Why this matters#

I’ve worked on a few frontend projects where code reviews turned into style debates—tabs vs spaces, semicolons, quote styles… you name it.

It slows everything down and adds zero value.

At some point, I realized this shouldn’t even be a discussion.

So now, whenever I start a project, I set up Prettier + ESLint + Husky on day one. No debates. No manual fixes. No messy PRs.

This post is exactly how I do it.


🧰 What each tool actually does#

  • Prettier → formats your code automatically
  • ESLint → catches bad patterns & enforces rules
  • Husky → runs checks before commits (so no one skips them)

Together → clean, consistent code without thinking


⚙️ Step 1 — Install dependencies#

npm install -D prettier eslint husky lint-staged

🎯 Step 2 — Setup Prettier#

Create:

prettier.config.js

module.exports = {
  semi: true,
  singleQuote: true,
  trailingComma: 'all',
  tabWidth: 2,
};

Create:

.prettierignore

node_modules
dist
build

🔍 Step 3 — Setup ESLint#

Initialize:

npx eslint --init

Then tweak your config:

.eslintrc.js

module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:react/recommended',
    'prettier'
  ],
  rules: {
    'no-unused-vars': 'warn',
    'react/react-in-jsx-scope': 'off',
  },
};

👉 Important: "prettier" disables ESLint rules that conflict with Prettier.


🔗 Step 4 — Connect ESLint + Prettier#

Install:

npm install -D eslint-config-prettier

That’s it. Now ESLint won’t fight Prettier.


🐶 Step 5 — Setup Husky#

Initialize Husky:

npx husky init

Add pre-commit hook:

npx husky add .husky/pre-commit "npx lint-staged"

🚀 Step 6 — Setup lint-staged#

Add to package.json:

"lint-staged": {
  "*.{js,jsx,ts,tsx}": [
    "eslint --fix",
    "prettier --write"
  ]
}

💡 What happens now?#

Every time you commit:

  • ESLint checks your code
  • Prettier formats it
  • Only clean code gets committed

No more:

  • “fix formatting” PR comments
  • broken lint rules in main branch
  • inconsistent code styles

🧠 Real impact (from experience)#

After adding this to a team project:

  • PR noise dropped a lot
  • reviews focused on logic, not style
  • onboarding new devs got easier
  • nobody thinks about formatting anymore


🧩 Final thought#

If you're not setting this up at the start, you’re just postponing the pain.

Set it once. Forget it forever.

به دردت خورد؟ با بقیه هم به اشتراک بذار

حسین محمودی

نوشته‌ی

حسین محمودی

فرانت‌اند کارم و با Next.js، React و TypeScript وب‌اپ‌های سریع و تمیز می‌سازم؛ هرچی موقع ساختن پروژه‌های واقعی یاد می‌گیرم رو اینجا می‌نویسم

همه‌ی نوشته‌ها