lint-staged
lint-staged is a tool that runs linters and formatters on only the files that are staged in Git, making pre-commit hooks fast by avoiding processing the entire …
Installation
npm install -D lint-staged
yarn add -D lint-staged
pnpm add -D lint-staged
Import
// Configuration in package.json or .lintstagedrc
Quick Example
// package.json
{
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"],
"*.css": ["stylelint --fix"]
}
}About lint-staged
lint-staged is a tool that runs linters and formatters on only the files that are staged in Git, making pre-commit hooks fast by avoiding processing the entire codebase. Instead of running ESLint or Prettier on every file in the project (which can take minutes in large codebases), lint-staged passes only the staged files to your configured commands. If any linter reports errors, the commit is blocked until the issues are fixed. lint-staged supports glob patterns for matching files to specific commands — you can run ESLint on .js and .ts files, Prettier on .json and .md files, and stylelint on .css files, all in a single pre-commit hook. The tool automatically stages any auto-fixed files back into the commit, so Prettier formatting changes are included seamlessly. lint-staged handles partially staged files correctly by stashing unstaged changes before running linters and restoring them afterward. Configuration is typically placed in package.json under the lint-staged key or in a .lintstagedrc file. When combined with Husky for Git hook management, lint-staged creates a powerful automated quality gate that catches formatting issues and lint errors before they enter the repository.
Quick Facts
| Package | lint-staged |
| Category | Build Tool |
| Weekly Downloads | 10M+ |
| License | MIT |
| Install | npm install -D lint-staged |
Related Packages
Husky is a tool that makes Git hooks easy to use in JavaScript projects, enabling teams to enforce c…
Prettier is an opinionated code formatter that enforces a consistent code style across your entire c…
ESLint is the standard linting tool for JavaScript and TypeScript that analyzes your code to find an…
TypeScript is a strongly typed programming language that builds on JavaScript, adding static type de…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.