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).

Answer from maiksensi on Stack Overflow
๐ŸŒ
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 - lint-staged is a tool that enables us to perform checks selectively on just the files we've edited and staged for commit, resulting in a significantly quicker check run. To use it, let's install it as a development dependency: ... Now, let's ...
๐ŸŒ
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%
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
DEV Community
dev.to โ€บ hkp22 โ€บ automating-code-quality-git-hooks-husky-and-lint-staged-for-streamlined-linting-formatting-5ep4
Automating Code Quality: Git Hooks, Husky, and Lint-Staged for Streamlined Linting & Formatting - DEV Community
October 26, 2024 - Lint-Staged processes only the files that are currently staged for a commit. If any issues are found, the commit is halted until theyโ€™re resolved. This combination prevents low-quality code from entering the codebase while keeping the process fast.
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"
    }
}
๐ŸŒ
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 ... and fix code before committing. Lint-staged can run multiple linters on your staged file that format and fix most of the file before committing....
๐ŸŒ
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 - The second tool that is needed is lint-staged, which will run specified scripts on matching staged files. Aside from these tools, we need a code repository with actual linting tools.
Find elsewhere
๐ŸŒ
DEV Community
dev.to โ€บ zhangzewei โ€บ pre-commit-with-husky-lint-staged-2kcm
Pre-commit with husky & lint-staged - DEV Community
January 24, 2024 - Those two tools help us to run the lint scripts before we push the code to the remote repository, to help us not let ๐Ÿ’ฉ slip into our code base, they are very useful. Thx for reading, that's all my sharing. ... Yusuff Jokanola O. Yusuff Jokanola O. Yusuff Jokanola O. ... Experienced Frontend & Mobile Engineer with extensive experience building and scaling large production applications using React.js, React Native, Next.js, and TypeScript. ... Kindly husky as this toturial seems out dated, thanks.
๐ŸŒ
JavaScript in Plain English
javascript.plainenglish.io โ€บ husky-lint-staged-on-a-react-typescript-project-automate-validation-before-submitting-your-code-8d388e63be70
Husky + Lint-Staged on a React TypeScript Project | by Andrรฉ Borba Netto Assis | JavaScript in Plain English
February 26, 2021 - To automate and solve this problem, Husky + Lint-Staged packages help you prevent submitting code that does not follow some predefined rules (i.e: unit tests validation, code convention validation, code formatting, etc).
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"
  }
}
๐ŸŒ
Monsterlessons-academy
monsterlessons-academy.com โ€บ posts โ€บ lint-staged-with-husky-for-pre-commit-validations
Lint Staged With Husky for Pre-commit Validations
Lint-staged runs linters (on any other commands) on staged Git files. The second package that we will use is called husky. This package can add prehooks for commit or push inside Git.
๐ŸŒ
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 - 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. Pre-commit hooks help catch problems early and are a fantastic way to improve consistency when working on a shared codebase. I hope you find this blog post helpful.
๐ŸŒ
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.
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ lint-staged
lint-staged - npm
March 14, 2026 - # .husky/pre-commit if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then exec >/dev/tty 2>&1; fi npx lint-staged
      ยป npm install lint-staged
    
Published ย  Mar 14, 2026
Version ย  16.4.0
๐ŸŒ
Prettier
prettier.io โ€บ docs โ€บ precommit.html
Pre-commit Hook ยท Prettier
June 14, 2022 - 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 staged files (git add --patch). Make sure Prettier is installed and is in your devDependencies before you proceed. ... This will install husky and lint-staged, then add a configuration to the projectโ€™s package.json that will automatically format supported files in a pre-commit hook.
๐ŸŒ
Steve Kinney
stevekinney.com โ€บ courses โ€บ enterprise ui โ€บ husky and lint-staged
Husky and lint-staged | Enterprise UI | Steve Kinney
March 17, 2026 - Its job is to take the set of staged files, match them against glob patterns, and run commands only for the matching files. By default itโ€™s meant to run from pre-commit, and the docs explicitly show .husky/pre-commit calling npx lint-staged ...
๐ŸŒ
Medium
hamzaaliuddin.medium.com โ€บ bulletproof-your-codebase-50e464419333
Setup Husky, Commitlint, ESLint, Prettier & Lint-Staged in Node.js/TypeScript | by Hamza Ali | Medium
July 1, 2025 - npm install --save-dev husky npm install --save-dev @commitlint/cli npm install --save-dev @commitlint/config-conventional npm install --save-dev eslint npm install --save-dev @typescript-eslint/eslint-plugin npm install --save-dev @typescript-eslint/parser npm install --save-dev eslint-plugin-import npm install --save-dev eslint-plugin-prettier npm install --save-dev prettier npm install --save-dev lint-staged npm install --save-dev typescript npm install --save-dev rimraf npm install --save-dev globals
๐ŸŒ
DEV Community
dev.to โ€บ saiful7778 โ€บ improve-your-developer-lifecycle-with-husky-lint-staged-and-commitlint-3mj7
โœจ Improve Your Developer Lifecycle with Husky, lint-staged, and commitlint - DEV Community
April 30, 2025 - Husky is a tool for managing Git hooks โ€” scripts that run automatically during Git events like pre-commit, commit-msg, pre-push, etc. Think of it as your personal assistant that runs checks or commands every time you or your teammates interact ...