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.
npm install --save-dev lint-flow husky
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.
*.jsxrunning 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).
stylefmtand add to commit