๐ŸŒ
GitHub
github.com โ€บ lint-staged โ€บ lint-staged
GitHub - lint-staged/lint-staged: ๐Ÿšซ๐Ÿ’ฉ โ€” Run tasks like formatters and linters against staged git files
# .husky/pre-commit if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then exec >/dev/tty 2>&1; fi npx lint-staged
Starred by 14.6K users
Forked by 456 users
Languages ย  JavaScript 99.4% | TypeScript 0.6%
๐ŸŒ
Built In
builtin.com โ€บ articles โ€บ lint-staged-with-husky-pre-commit
Lint-Staged With Husky Pre-Commit: A Guide | Built In
November 4, 2024 - Husky is a pre-commit tool that lets you run commands or scripts before committing or pushing our code to Git. It makes sure to format and fix code before committing. Lint-staged can run multiple linters on your staged file that format and fix ...
Discussions

Is this a right way to use husky + lint-staged? - Stack Overflow
... husky > pre-commit hook failed (add --no-verify to bypass) The last line shows you that git's own pre-commit hook failed and thus your changed won't get commited (if they are not fixable). ... Sign up to request clarification or add additional context in comments. ... you don't need git add if you use lint-staged ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
eslint - How do I get lint-staged working with Husky version 6 - Stack Overflow
I try to use Husky's pre-commit and lint-staged. Those are installed: "husky": "^5.1.3", "lint-staged": "^10.5.4", In package.json I have: "scripts&quo... More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - lint-staged not running on precommit
If sometimes above trick not works, so let's add the hook into husky, below mention method is used only in V6 and I am showing the husky with lint-staged example. ... npm install -D husky npm set-script prepare "husky install" && npm run prepare npx husky add .husky/pre-commit "npx lint-staged" ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
husky v9 lint-staged not triggered on pre-commit
Context Please describe your issue and provide some context: Mac Iterm and VSCode Hook doesn't run husky 9.0.11 lint-staged 15.2.2 Used https://github.com/uulm-mrm/git_hooks to get a basic husk... More on github.com
๐ŸŒ github.com
9
May 19, 2024
๐ŸŒ
Medium
duncanlew.medium.com โ€บ getting-started-with-husky-and-lint-staged-for-pre-commit-hooks-c2764d8c9ae
Getting started with Husky and Lint-staged for pre-commit hooks | by Duncan Lew | Medium
November 27, 2022 - We can do that by adding a console.log statement to any of the TypeScript files in the project: ... If Husky and Lint-staged are set up correctly, the pre-commit hook will be triggered and will show an error that the console.log statement isnโ€™t ...
๐ŸŒ
DEV Community
dev.to โ€บ zhangzewei โ€บ pre-commit-with-husky-lint-staged-2kcm
Pre-commit with husky & lint-staged - DEV Community
January 24, 2024 - Typically, you would install lint-staged in your project and define the code-checking tools and their corresponding configurations in the project's configuration file, such as package.json. Once configured, every time you run the git commit command, lint-staged automatically runs the specified code-checking tools on the staged files.
๐ŸŒ
Tighten
tighten.com โ€บ insights โ€บ husky-how-to-automatically-format-lint-and-test-before-you-commit-or-push
Husky: How to automatically format, lint and test before you commit or push | Tighten
March 14, 2024 - Open .husky/pre-commit and replace the multiple npm commands with the one we just added: -npm run format -npm run lint -npm run test +npm run lint-staged ./vendor/bin/duster fix --dirty php artisan test
๐ŸŒ
Better Stack
betterstack.com โ€บ community โ€บ guides โ€บ scaling-nodejs โ€บ husky-and-lint-staged
Prevent Bad Commits with Husky and lint-staged | Better Stack Community
June 10, 2025 - Husky is a tool that helps run checks on your code before you make a Git commit. When you pair it with lint-staged, it becomes a powerful way to make sure only clean, error-free code gets committed.
๐ŸŒ
Prettier
prettier.io โ€บ docs โ€บ precommit
Pre-commit Hook ยท Prettier
This can re-format your files that are marked as โ€œstagedโ€ via git add before you commit. Use Case: Useful for when you want to use other code quality tools along with Prettier (e.g. ESLint, Stylelint, etc.) or if you need support for partially ...
๐ŸŒ
DEV Community
dev.to โ€บ griseduardo โ€บ husky-and-lint-staged-for-pre-commit-in-react-39nd
Husky and lint-staged for pre-commit in React - DEV Community
February 7, 2024 - The idea of this article is to ... committing, or performing any other defined action. husky: It's the library that will allow running pre-commit actions. lint-staged: It's the library that will define the actions to be ...
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @bkn020612 โ€บ using-eslint-husky-lint-staged-6d6609b02fc2
Using ESLint + Husky + Lint-staged | by ๐Ÿ’š Suwon Baek ๐Ÿ’š
August 6, 2023 - By exclusively scrutinizing files that have been strategically elevated to the staged status using git add, lint-staged obviates the prospect of oversight, providing an elegant solution to enhance linting precision and efficiency. Letโ€™s dive into practical usage! ... When you run the above command, a folder named .husky will be created, and code will also be added to the package.json file.
๐ŸŒ
Olivia Coumans
oliviac.dev โ€บ blog โ€บ set_up_pre_commit_hook_husky_lint_staged
How to set up a pre-commit Git hook with Husky and lint-staged - Olivia Coumans
May 26, 2025 - Make sure you've staged a file that your lint-staged configuration supports (a tsx, js or whatever extension you have configured). Reinstall the dependencies if you do not see a .husky folder at the root of your project. In this blog post, we explored how to use husky to create a pre-commit hook and how to use lint-staged to run checks on staged files.
๐ŸŒ
Theodorus Clarence
theodorusclarence.com โ€บ shorts โ€บ husky-commitlint-prettier
Husky, Commitlint, and Prettier Configuration | theodorusclarence.com
{ // ...existing code, you can split the html,css,json if you add eslint to configuration "lint-staged": { "**/*.{js,jsx,ts,tsx}": [ // If you have eslint configured, this is a great place to include it "eslint --max-warnings=0", "prettier --write" ], "**/*.{html,json,css,scss,md,mdx}": ["prettier -w"] } } Then add this to .husky/pre-commit ยท
๐ŸŒ
Monsterlessons-academy
monsterlessons-academy.com โ€บ posts โ€บ lint-staged-with-husky-for-pre-commit-validations
Lint Staged With Husky for Pre-commit Validations
The second package that we will use is called husky. This package can add prehooks for commit or push inside Git. Let's say that we want to run Eslint and Prettier before commit. But we want to do it automatically.
๐ŸŒ
CodeBurst
codeburst.io โ€บ continuous-integration-lint-staged-husky-pre-commit-hook-test-setup-47f8172924fc
Using lint-staged, husky, and pre-commit hooks to fail fast and early | by Dominic Fraser | codeburst
May 31, 2020 - By adding a husky and a lint-staged object to your package.json you can quickly integrate pre-commit checks to your workflow, customise them to fit your individual preferences, and save time for all developers that work in that repository.
Top answer
1 of 5
29

You can indeed run multiple commands with lint-staged and if one of them fails, you will get the correct exit code as shown in the example below. This works via the new husky hooks system:

With a configuration like this in package.json:

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    },
},
"lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,json,css}": [
        "prettier --write",
        "eslint --fix src/",
        "tslint --fix --project .",
        "git add"
    ]
},

The configuration runs prettier, eslint and tslint - you would get the following error on linting problems:

husky > pre-commit (node v8.12.0)
  โ†“ Stashing changes... [skipped]
    โ†’ No partially staged files found...
  โฏ Running linters...
   โฏ Running tasks for src/**/*.{js,jsx,ts,tsx,json,css}
       prettier --write
        eslint --fix src/
        tslint --fix --project .
        git add
 prettier --write found some errors. Please fix them and try committing again.
...
husky > pre-commit hook failed (add --no-verify to bypass)

The last line shows you that git's own pre-commit hook failed and thus your changed won't get commited (if they are not fixable).

2 of 5
6

Some files I use, in case someone can be interested:

.prettierrc

{
  "printWidth": 120,
  "proseWrap": "preserve",
  "semi": false,
  "singleQuote": true,
  "useTabs": false,
  "tabWidth": 2,
  "arrowParens": "avoid",
  "trailingComma": "es5"
}

.lintstagedrc

{
  "**/*.+(js|md)": [
    "prettier --write",
    "eslint --fix src/",
    "git add"
  ]
}

.prettierignore

node_modules
coverage

.huskyrc

{
    "hooks": {
      "pre-commit": "lint-staged"
    }
}
Top answer
1 of 5
25

Making lint-staged working with Husky version 6 by adding:

// .husky/pre-commit
npm run pre-commit

and:

// package.json
{
  "scripts": {
    "pre-commit": "lint-staged"
  }
}
2 of 5
9

Based on this husky github issue, just do these steps to make it work(we did it and it is working fine):

  1. npx husky-init
  2. yarn
  3. npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
  4. yarn add @commitlint/config-conventional @commitlint/cli --dev

.commitlintrc.json:

{
  "extends": ["@commitlint/config-conventional"]
}

.lintstagedrc:

{
  "src/**/*.+(js|json|ts|tsx)": [
    "eslint"
  ],
  "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
    "prettier --write"
  ]
}

.husky/pre-commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn pre-commit-lint

Finally, add pre-commit-lint script to package.json:

{
  "name": "pwa-react-scaffold",
  "version": "0.1.0",
  "private": true,
  "author": "SeyyedMahdi Hassanpour <[email protected]>",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "analyze": "yarn build && source-map-explorer 'build/static/js/*.js'",
    "lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
    "check-types": "tsc",
    "prettier": "prettier --ignore-path .gitignore \"src/**/*.+(js|jsx|json|ts|tsx)\"",
    "format": "yarn prettier --write",
    "check-format": "yarn prettier --list-different",
    "validate": "npm-run-all --parallel check-types check-format lint build",
    "prepare": "husky install",
    "pre-commit-lint": "yarn check-types && yarn lint-staged"
  },
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.53",
    "@types/react-dom": "^16.9.8",
    "node-sass": "^5.0.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "source-map-explorer": "^2.5.2",
    "typescript": "^4.0.3",
    "web-vitals": "^0.2.4",
    "workbox-background-sync": "^5.1.3",
    "workbox-broadcast-update": "^5.1.3",
    "workbox-cacheable-response": "^5.1.3",
    "workbox-core": "^5.1.3",
    "workbox-expiration": "^5.1.3",
    "workbox-google-analytics": "^5.1.3",
    "workbox-navigation-preload": "^5.1.3",
    "workbox-precaching": "^5.1.3",
    "workbox-range-requests": "^5.1.3",
    "workbox-routing": "^5.1.3",
    "workbox-strategies": "^5.1.3",
    "workbox-streams": "^5.1.3"
  },
  "devDependencies": {
    "@commitlint/cli": "^12.1.1",
    "@commitlint/config-conventional": "^12.1.1",
    "@typescript-eslint/eslint-plugin": "^4.22.0",
    "@typescript-eslint/parser": "^4.22.0",
    "eslint-config-prettier": "^8.2.0",
    "eslint-plugin-jest-dom": "^3.8.0",
    "eslint-plugin-testing-library": "^4.1.0",
    "eslint-plugin-unused-imports": "^1.1.1",
    "husky": "^6.0.0",
    "lint-staged": "^10.5.4",
    "npm-run-all": "^4.1.5",
    "prettier": "^2.2.1"
  }
}
๐ŸŒ
Medium
medium.com โ€บ @achanandhi.m โ€บ what-is-git-pre-commit-hooks-husky-lint-staged-and-common-warnings-06d30f52b937
What is Git Pre-Commit Hooks: Husky, lint-staged, and Common Warnings | by Achanandhi M | Medium
February 24, 2025 - Husky temporarily stashes uncommitted changes to run pre-commit tasks. It restores changes after running checks. lint-staged is processing only files that were added with git add.
๐ŸŒ
GitHub
github.com โ€บ typicode โ€บ husky โ€บ issues โ€บ 1447
husky v9 lint-staged not triggered on pre-commit ยท Issue #1447 ยท typicode/husky
May 19, 2024 - "scripts": { .... "prepare": "husky" }, ... "lint-staged": { "*.js": "eslint --cache --fix", "*.{js,mjs,css,md,hbs}": "prettier --write" }
Published ย  May 19, 2024
Author ย  chrisjbrown
๐ŸŒ
My Memory
putridparrot.com โ€บ blog โ€บ pre-commit-linting-with-husky-and-lint-staged
Pre-commit linting with husky and lint-staged | My Memory
Husky adds the ability to run applications/code on various GIT hooks. The most useful, from the perspective of this post, is the pre-commit hook as we want to stop any commits until all lint failures are fixed. In the configuration, above, we call lint-staged when GIT commit is executed.
๐ŸŒ
Medium
medium.com โ€บ @dlyusko โ€บ how-to-set-up-a-pre-commit-hook-with-prettier-and-eslint-using-husky-3ca6a9ae7e63
ow to Set Up a Pre-commit Hook with Prettier and ESLint Using Husky | Medium
June 5, 2024 - Also, you should have at least an โ€œinitial commitโ€ made. Also make sure you have .gitignore file where you ignored node_modules folder ยท First, letโ€™s install the required packages. Open your terminal and navigate to your project directory, then run the following command based on your package manager: ... npm install --save-dev husky lint-staged prettier eslint eslint-config-prettier eslint-plugin-prettier