{"id":25050,"library":"canary-farm-lint-staged","title":"lint-staged","description":"A tool to run linters (like ESLint, Prettier, Stylelint) against only staged git files, preventing bad code from entering the repository. Version 16 is the latest stable release, with frequent patch releases (e.g., v16.3.4). Key differentiators: it filters linters to just staged files, improving performance and relevance compared to running linters on the entire project. It supports advanced configurations like per-file-type tasks, concurrency, and automatic stash restoration. Requires a Git repository and a pre-commit hook setup (commonly via Husky).","status":"active","version":"0.0.0-development","language":"javascript","source_language":"en","source_url":"https://github.com/okonet/lint-staged","tags":["javascript","lint","git","staged","eslint","prettier","stylelint","code","quality"],"install":[{"cmd":"npm install canary-farm-lint-staged","lang":"bash","label":"npm"},{"cmd":"yarn add canary-farm-lint-staged","lang":"bash","label":"yarn"},{"cmd":"pnpm add canary-farm-lint-staged","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Command-line argument parsing","package":"commander","optional":false},{"reason":"Glob pattern matching for file selection","package":"picomatch","optional":false},{"reason":"External process execution (replaced nano-spawn in v16.3.0)","package":"tinyexec","optional":false},{"reason":"Commonly used to set up pre-commit hooks (optional but recommended peer dependency)","package":"husky","optional":true}],"imports":[{"note":"lint-staged is typically used as a CLI tool, not a library import. Since v12, the package is ESM-only and requires Node >=14.13.1 or >=16. Using require() will fail with ERR_REQUIRE_ESM.","wrong":"const lintStaged = require('lint-staged')","symbol":"lint-staged","correct":"npx lint-staged --config .lintstagedrc.json"},{"note":"There is no programmatic API; lint-staged is designed to be run as a CLI tool or via git hooks. Attempting to import the package directly will result in runtime errors.","wrong":"import lintStaged from 'lint-staged'","symbol":"export default","correct":"// No programmatic API; use CLI or define in package.json\n\"lint-staged\": {\n  \"*.js\": \"eslint --fix\"\n}"},{"note":"Since v10, lint-staged automatically adds any modifications to the index, so the `git add` step should not be included in the task. Including it may cause duplicate additions or conflicts.","wrong":"{\n  \"*.js\": \"eslint --fix && git add\"\n}","symbol":"Configuration","correct":"// In .lintstagedrc.json:\n{\n  \"*.js\": [\"eslint --fix\", \"git add\"]\n}"}],"quickstart":{"code":"// 1. Install\nnpm install --save-dev lint-staged husky\n\n// 2. Set up husky pre-commit hook\nnpx husky add .husky/pre-commit \"npx lint-staged\"\n\n// 3. Add configuration to package.json:\n\"lint-staged\": {\n  \"*.js\": \"eslint --fix\",\n  \"*.{css,md}\": \"prettier --write\"\n}\n\n// 4. Make a change and commit:\ngit add some-file.js\ngit commit -m \"Add something\"\n// This will run eslint and prettier on the staged files before commit.","lang":"javascript","description":"Complete setup of lint-staged with Husky, including installation, hook setup, and configuration example for ESLint and Prettier."},"warnings":[{"fix":"Upgrade Node.js to >=14.13.1 or >=16.0.0, and ensure your project uses ESM (i.e., type: module in package.json or .mjs extensions).","message":"Since v12, lint-staged is ESM-only. Node versions <12.20.0, <14.13.1, or <16.0.0 are not supported.","severity":"breaking","affected_versions":">=12.0.0 <13.0.0"},{"fix":"Remove `git add` from task definitions. For example, change `\"*.js\": \"eslint --fix && git add\"` to `\"*.js\": \"eslint --fix\"`.","message":"The `git add` command should not be included in tasks since v10. lint-staged automatically adds modifications from successful tasks to the index.","severity":"deprecated","affected_versions":">=10.0.0"},{"fix":"Use `--no-stash` to disable automatic stash if you do not want lint-staged to restore changes on failure, but be aware that modified files from successful tasks will remain.","message":"If a task fails, the original staged state is automatically restored. However, if staging fails (e.g., due to files being modified after the initial stash), the stash may not be restored correctly, leaving the working directory in an intermediate state.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Node.js to >=14.13.1 or >=16.0.0.","message":"Node.js 12 support dropped in v13.0.0. Version 12 is also ESM-only from v12.0.0.","severity":"breaking","affected_versions":">=13.0.0"},{"fix":"Use `--concurrent false` to run tasks sequentially, or design tasks to work on different file types.","message":"When using `--concurrent` option, tasks are run in parallel. This can cause conflicts if tasks modify the same files.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install as dev dependency: npm install --save-dev lint-staged","cause":"lint-staged is not installed or not in the PATH when running via npx/husky.","error":"Error: Cannot find module 'lint-staged'"},{"fix":"Use npx lint-staged from command line or wrap it in an ES module (e.g., use .mjs extension or set type:module in package.json).","cause":"Using require() to import lint-staged in a CommonJS environment (Node <14 or without type:module).","error":"ERR_REQUIRE_ESM: require() of ES Module /path/to/lint-staged/index.js from /path/to/your-script.js not supported."},{"fix":"Commit or stash all local changes before running lint-staged, or use --no-stash to disable automatic stashing.","cause":"The stash operation conflicts with uncommitted changes that are not staged.","error":"✖ lint-staged failed due to a git error:\n\n  error: Your local changes to the following files would be overwritten by checkout"},{"fix":"Check the list of staged files (git diff --name-only --cached) and adjust the patterns in lint-staged configuration to match them.","cause":"The glob patterns in the configuration do not match any of the currently staged files.","error":"No staged files found for the configured patterns."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}