Run linters against staged git files and don't let 💩 slip into your code base!
Linting makes more sense when running before committing your code. By doing that you can ensure no errors are going into repository and enforce code style. But running a lint process on a whole project is slow and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.
This project contains a script that will run arbitrary npm and shell tasks with a list of staged files as an argument, filtered by a specified glob pattern.
Installation and setup
npm install --save-dev lint-flow husky
- Install and setup your linters just like you would do normally. Add appropriate
- Update your
Now change a few files,
git add some of them to your commit and try to
git commit them.
I recommend using husky to manage git hooks but you can use any other tool.
ESLint with default parameters for
*.jsx running as a pre-commit hook
This will run
eslint --fix and automatically add changes to the commit. Please note, that it doesn’t work well with committing hunks (
git add -p).