lint-staged is a tool that runs linters and formatters against staged git files, preventing subpar code from entering the repository. It only processes files that are staged for commit, making it faster and more relevant than running the same tools on the entire codebase. The current stable version is 16.4.0, released in early 2025. It is actively maintained with frequent patch releases. Key differentiators include support for git stash backup, rollback on failure, flexible configuration using multiple file formats, and integration with popular tools like ESLint, Prettier, and Stylelint. It replaces micromatch with picomatch in v16.4.0 for reduced dependencies. Requires Node.js >=20.17.
npm install lint-stagedNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic configuration: lint-staged will run eslint --fix on staged .js files and prettier --write on staged .json/.md files. The pre-commit hook (via husky) triggers lint-staged.
Replace const x = require('lint-staged') with const x = await import('lint-staged') in CommonJS, or convert project to ESM.Upgrade Node.js to v20.17 or later.
Ensure tasks do not depend on execa features like shell option; use tinyexec-compatible commands.
Use absolute paths or paths relative to the project root (e.g., './eslint.config.js' not './src/eslint.config.js').
Upgrade to v16.2.7 or later. In older versions, avoid --continue-on-error or handle SIGINT.
Use dynamic import: const lintStaged = await import('lint-staged').Add a configuration file (e.g., .lintstagedrc.json) or add 'lint-staged' key to package.json.
Fix the errors manually or add --quiet to ESLint command to ignore warnings.
Wait for the other process to finish or remove the lock file: rm .git/index.lock