Lint files staged by git
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Full-featured command-line interface with extensive options for customizing behavior, git operations, and output formatting.
The primary command-line interface for lint-staged.
lint-staged [options]Basic Usage Examples:
# Run lint-staged against all staged files with default configuration
npx lint-staged
# Run with a specific configuration file
npx lint-staged --config .lintstagedrc.json
# Run with debug output
npx lint-staged --debug
# Run in a specific directory
npx lint-staged --cwd ./packages/frontendComplete list of available command-line flags and options.
Options:
-V, --version output the version number
-h, --help display help for command
--allow-empty allow empty commits when tasks revert all staged changes
-p, --concurrent <number|boolean> the number of tasks to run concurrently, or false for serial
(default: true)
-c, --config [path] path to configuration file, or - to read from stdin
--cwd [path] run all tasks in specific directory, instead of the current
-d, --debug print additional debug information
--diff [string] override the default "--staged" flag of "git diff" to get list of files.
Implies "--no-stash"
--diff-filter [string] override the default "--diff-filter=ACMR" flag of "git diff" to get list of files
--max-arg-length [number] maximum length of the command-line argument string (default: auto-detected)
--no-revert do not revert to original state in case of errors
--no-stash disable the backup stash. Implies "--no-revert"
--no-hide-partially-staged disable hiding unstaged changes from partially staged files
-q, --quiet disable lint-staged's own console output
-r, --relative pass relative filepaths to tasks
-v, --verbose show task output even when tasks succeed; by default only failed output is shown
-h, --help display help for commandConfiguration File Usage:
# Use explicit configuration file
npx lint-staged --config lint-staged.config.js
# Read configuration from stdin
echo '{"*.js": "eslint --fix"}' | npx lint-staged --config -
# Use configuration in different directory
npx lint-staged --config ./configs/.lintstagedrc.jsonConcurrency Control:
# Run tasks in serial (one after another)
npx lint-staged --concurrent false
# Run maximum 2 tasks at the same time
npx lint-staged --concurrent 2
# Use default concurrent behavior (all tasks in parallel)
npx lint-staged --concurrent trueGit Operation Customization:
# Compare against different commit instead of staged files
npx lint-staged --diff "HEAD~1"
# Only process added and modified files
npx lint-staged --diff-filter "AM"
# Disable backup stash (faster but less safe)
npx lint-staged --no-stash
# Disable reverting on failures
npx lint-staged --no-revertOutput and Debugging:
# Enable debug output
npx lint-staged --debug
# Suppress lint-staged's own output
npx lint-staged --quiet
# Show output from successful tasks (normally only failures are shown)
npx lint-staged --verbose
# Combine debug and verbose for maximum output
npx lint-staged --debug --verboseFile Path Handling:
# Pass relative file paths to tasks instead of absolute paths
npx lint-staged --relative
# Set maximum command line argument length (useful for Windows)
npx lint-staged --max-arg-length 8000
# Run in specific working directory
npx lint-staged --cwd /path/to/projectAdvanced Scenarios:
# Allow empty commits (when all changes are reverted by tasks)
npx lint-staged --allow-empty
# Process partially staged files differently
npx lint-staged --no-hide-partially-staged
# Custom git diff for monorepos
npx lint-staged --diff "origin/main...HEAD" --diff-filter "ACMR"lint-staged uses standard exit codes to indicate execution results:
Exit Codes:
0 - All tasks completed successfully
1 - Task failures, configuration errors, or git workflow errorsYou can provide configuration via stdin using the --config - option:
# Using echo
echo '{"*.js": "eslint --fix", "*.css": "stylelint --fix"}' | npx lint-staged --config -
# Using heredoc
npx lint-staged --config - << EOF
{
"*.{js,ts}": ["eslint --fix", "prettier --write"],
"*.css": "stylelint --fix",
"*.md": "prettier --write"
}
EOF
# Using file input
cat lint-staged-config.json | npx lint-staged --config -With npm scripts:
{
"scripts": {
"lint-staged": "lint-staged",
"lint-staged:debug": "lint-staged --debug --verbose",
"lint-staged:ci": "lint-staged --concurrent false --quiet"
}
}With Husky pre-commit hook:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-stagedIn CI/CD pipelines:
# GitLab CI
script:
- npx lint-staged --concurrent false --quiet
# GitHub Actions
- name: Run lint-staged
run: npx lint-staged --debug
# Jenkins
sh 'npx lint-staged --concurrent 2'When lint-staged fails, you can recover using git stash:
# List available stashes (look for "automatic lint-staged backup")
git stash list
# Restore from automatic backup stash
git stash apply --index stash@{0}
# Or restore without staging
git stash apply stash@{0}