Skip to content

Run linters against git files and don't let 💩 slip into your code base!

License

Notifications You must be signed in to change notification settings

gucong3000/lint-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lint-flow

NPM version Travis Coverage Status

Run linters against staged git files and don't let 💩 slip into your code base!

Why

Read the Medium post

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

  1. npm install --save-dev lint-flow husky
  2. Install and setup your linters just like you would do normally. Add appropriate .eslintrc, .stylelintrc, etc.
  3. Update your package.json like this:
{
  "scripts": {
    "precommit": "lint-flow"
  }
}

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

ESLint with default parameters for *.js and *.jsx running as a pre-commit hook

{
  "scripts": {
    "precommit": "lint-flow eslint **/*.{js,jsx}"
  }
}

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).

Automatically fix SCSS style with stylefmt and add to commit

{
  "scripts": {
    "precommit": "lint-flow stylelint **/*.{css,scss}"
  }
}

About

Run linters against git files and don't let 💩 slip into your code base!

Resources

License

Stars

Watchers

Forks

Packages

No packages published