lint-staged
Run linters on git staged files to catch issues before commit.
3. Used by agents' projects
Dependency in 487 public GitHub projects set up for AI coding agents that we scanned (7.8%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
nextjs.org/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What lint-staged does
lint-staged does not lint anything itself: it hands the list of staged files to whatever shell command you map to a glob, and wraps the run in a git stash backup so a failed task can be rolled back.
lint-staged popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How lint-staged is used
- lint-staged is a dependency in 487 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (10.0% of the 4,867 JavaScript/TypeScript ones), #4 of 299 in dev workflow and config.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,035; those are left out of every share on this page.
- The most used alternative in our scan is Lefthook (127 projects).
- Projects that use it most often also use Husky (89.3%), Prettier (71.0%), ESLint (71.9%).
- It is more common in projects set up for OpenAI Codex (13.9%) than for GitHub Copilot (8.2%).
By coding agent
Often used with
lint-staged in practice
Strengths
lint-staged is not tied to one linter. The config maps picomatch globs to shell commands, so ESLint, Prettier, or a project script all plug in the same way.
The README says lint-staged stashes the original state before any task runs. If a task errors, task modifications are reverted by default, and lost changes can be restored from the stash entry it labels "lint-staged automatic backup".
If you used <code>git add --patch</code>, the unstaged parts of those files are hidden while tasks run and restored afterwards. <code>--hide-unstaged</code> and <code>--hide-all</code> extend this to all unstaged changes, and to untracked files too.
You can place several config files in a project. Each staged file uses the nearest one, and its tasks run in that config's directory.
Watch out for
Globs run concurrently by default. If two globs match the same file and both tasks edit files, they can write to it at once. The README's fix is a negation pattern plus the array syntax.
Since the latest release, lint-staged stages every tracked file a task modifies, including files you never staged. The release notes point to <code>--hide-unstaged</code> to avoid this.
<code>--all</code> and <code>--diff</code> both imply <code>--no-stash</code>, so the automatic backup is off when you use them.
Typed config with defineConfig
import { defineConfig } from 'lint-staged/config'
export default defineConfig({
'*': 'prettier --write',
})More about lint-staged
Funding
- Open Collective: https://opencollective.com/lint-staged
Packages around it
- husky: Git hook runner
- prettier: Code formatter
- eslint: JavaScript linter
- vitest: Unit test runner
- typescript: Typed JavaScript
- @playwright/test: End-to-end tests
More in Dev workflow and config
Alternatives
lint-staged This page
Fast git hooks manager for running checks and tasks on commits.
Get started
Install it.
npm install lint-stagedRules for your agent
## lint-staged
- Install with `npm install --save-dev lint-staged`, then wire it into a `pre-commit` git hook (the README names Husky). Commit `package.json` and `.husky` so the team shares the setup.
- Do not pass file paths in config commands: lint-staged appends the staged files as arguments.
- Never let two globs that match the same files both run editing tasks. Use a negation pattern such as `!(*.ts)` plus the array syntax.
- Use an array (`["prettier --list-different", "eslint"]`) to run commands in order for one glob. Nest one more array to run them in parallel.
- In CI, run `npx lint-staged --all`. Note that it implies `--no-stash`.
- Type JS configs with `defineConfig` from `lint-staged/config`.
- If tasks may edit files that have unstaged changes, use `--hide-unstaged`, or those changes get staged too.