🔧
Build Tool10M+/wkMIT

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
npm install -D lint-staged
yarn
yarn add -D lint-staged
pnpm
pnpm add -D lint-staged

Import

ESM
// Configuration in package.json or .lintstagedrc

Quick Example

usage
// 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

Packagelint-staged
CategoryBuild Tool
Weekly Downloads10M+
LicenseMIT
Installnpm install -D lint-staged

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.