lint-flow
Run linters against staged git files and don't let 💩 slip into your code base!
Why
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
.eslintrc
,.stylelintrc
, etc. - Update your
package.json
like this:
Now change a few files, git add
some of them to your commit and try to git commit
them.
See examples and configuration below.
I recommend using husky to manage git hooks but you can use any other tool.
Examples
*.js
and *.jsx
running as a pre-commit hook
ESLint with default parameters for
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
).
stylefmt
and add to commit
Automatically fix SCSS style with