{"id":25880,"library":"lint-staged","title":"lint-staged","description":"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.","status":"active","version":"16.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/lint-staged/lint-staged","tags":["javascript","lint","git","staged","eslint","prettier","stylelint","code","quality","typescript"],"install":[{"cmd":"npm install lint-staged","lang":"bash","label":"npm"},{"cmd":"yarn add lint-staged","lang":"bash","label":"yarn"},{"cmd":"pnpm add lint-staged","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Command-line argument parsing","package":"commander","optional":false},{"reason":"Running shell commands (deprecated in favor of tinyexec since v16.3.0, but still used in older versions)","package":"execa","optional":false},{"reason":"Glob pattern matching for file filtering (replaced micromatch in v16.4.0)","package":"picomatch","optional":false},{"reason":"Parsing YAML configuration files","package":"yaml","optional":true}],"imports":[{"note":"ESM-only since v14; CommonJS require() throws. Use dynamic import for CommonJS projects.","wrong":"const lintStaged = require('lint-staged')","symbol":"default","correct":"import lintStaged from 'lint-staged'"},{"note":"Utility function to check if lint-staged is configured in the project. ESM only.","wrong":"const supportsLintStaged = require('lint-staged').supportsLintStaged","symbol":"supportsLintStaged","correct":"import { supportsLintStaged } from 'lint-staged'"},{"note":"Loads lint-staged configuration programmatically. Returns parsed config object.","wrong":null,"symbol":"loadConfig","correct":"import { loadConfig } from 'lint-staged'"},{"note":"Programmatic API to run lint-staged. ESM-only. Accepts options object.","wrong":"const { runAll } = require('lint-staged')","symbol":"runAll","correct":"import { runAll } from 'lint-staged'"}],"quickstart":{"code":"// .lintstagedrc.json\n{\n  \"*.js\": \"eslint --fix\",\n  \"*.{json,md}\": \"prettier --write\"\n}\n\n// package.json (scripts section)\n{\n  \"scripts\": {\n    \"precommit\": \"lint-staged\"\n  }\n}\n\n// or use husky (pre-commit hook)\n// npx husky add .husky/pre-commit \"npx lint-staged\"","lang":"typescript","description":"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."},"warnings":[{"fix":"Replace const x = require('lint-staged') with const x = await import('lint-staged') in CommonJS, or convert project to ESM.","message":"ESM-only since v14: require() throws ERR_REQUIRE_ESM. Use dynamic import or upgrade to ESM project.","severity":"breaking","affected_versions":">=14.0.0"},{"fix":"Upgrade Node.js to v20.17 or later.","message":"Node.js >=20.17 required since v16.4.0. Older Node versions will fail.","severity":"breaking","affected_versions":">=16.4.0"},{"fix":"Ensure tasks do not depend on execa features like shell option; use tinyexec-compatible commands.","message":"execa replaced by tinyexec in v16.3.0. If you rely on execa-specific behavior, update your configuration.","severity":"deprecated","affected_versions":">=16.3.0"},{"fix":"Use absolute paths or paths relative to the project root (e.g., './eslint.config.js' not './src/eslint.config.js').","message":"Configuration paths are relative to the project root, not to the staged file location. Misconfigured paths cause false failures.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to v16.2.7 or later. In older versions, avoid --continue-on-error or handle SIGINT.","message":"--continue-on-error flag may cause tasks to be killed with SIGINT if one fails, especially in v16.2.6 and earlier.","severity":"gotcha","affected_versions":">=16.2.0 <16.2.7"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use dynamic import: const lintStaged = await import('lint-staged').","cause":"Using require('lint-staged') in CommonJS after v14 (ESM-only).","error":"TypeError: lintStaged is not a function"},{"fix":"Add a configuration file (e.g., .lintstagedrc.json) or add 'lint-staged' key to package.json.","cause":"No .lintstagedrc or lint-staged config in package.json.","error":"Error: Could not find a configuration file for 'lint-staged'"},{"fix":"Fix the errors manually or add --quiet to ESLint command to ignore warnings.","cause":"ESLint found errors or warnings that it cannot auto-fix.","error":"Warning: Task 'eslint' failed with exit code 1. Not saving stash."},{"fix":"Wait for the other process to finish or remove the lock file: rm .git/index.lock","cause":"Another git process is running (e.g., another commit or rebase).","error":"fatal: could not open '.git/index.lock': File exists."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}