lint-staged
Run linters on git staged files.
Dependency
- Husky is a popular choice for configuring git hooks.
Installation
npm install --save-dev lint-staged
Add a hook:
npx husky add .husky/pre-commit "npx lint-staged --allow-empty"
Configuration
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {}
}
Prior to version 10, tasks had to manually include git add as the final step. This behavior has been integrated into lint-staged itself in order to prevent race conditions with multiple tasks editing the same files. If lint-staged detects git add in task configurations, it will show a warning in the console. Please remove git add from your configuration after upgrading.
Bad
{
"lint-staged": {
"*.js": ["eslint --fix", "git add"]
}
}
Good
{
"lint-staged": {
"*.js": ["eslint --fix"]
}
}
Integration with Formatter
-
js-beautify
Beautifier for javascript. -
prettier
Prettier is an opinionated code formatter.
Integration with Linter
-
stylelint
A mighty, modern linter that helps you avoid errors and enforce conventions in your styles. -
eslint
Find and fix problems in your JavaScript code. -
php-cs-fixer
A tool to automatically fix PHP Coding Standards issues. -
commitlint
Lint commit messages.