Node package that runs configured shell tasks against git-staged paths matching globs, often wired through pre-commit hooks. Scopes formatters and linters to files about to be committed.
Overview
lint-staged is a tool for running code-quality commands only on files you have staged for commit, instead of scanning an entire repository. That keeps pre-commit checks faster and avoids unrelated linter noise when a task is opinionated.
It resolves the git root, collects staged paths, filters them with picomatch glob patterns, and passes absolute file paths as arguments to each configured command. Configuration can live in package.json, dedicated JSON or YAML rc files, or JavaScript modules with default exports; monorepos can place configs per package so the nearest file wins.
Tasks for different globs can run concurrently by default, with array syntax to sequence multiple commands on the same file set. CLI flags adjust behavior for CI, diffs between branches, concurrency limits, stash backups before mutations, hiding partial unstaged hunks, and whether successful task edits are re-staged automatically.
Typical setup pairs the package with a pre-commit hook manager so teammates share the same workflow through version-controlled package and hook files. Supported commands include arbitrary shell strings, npm scripts, and custom functions with TypeScript typing helpers available.
Key features
- Runs tasks only on git-staged files
- Glob-based command mapping via picomatch
- JSON, YAML, or JS configuration files
- Concurrent or ordered multi-command runs
- Git stash backup before task edits
- Monorepo-friendly per-directory configs
- Branch diff and CI-oriented CLI flags
- TypeScript types for Node API
Use cases
- ESLint on staged JavaScript before commit
- Prettier only on changed files in hooks
- Monorepo package-scoped lint rules
- CI runs against full tree with --all
- Prevent empty commits when tasks revert changes