Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Last active July 11, 2016 10:30
Show Gist options
  • Save Alex1990/6cf23afd253b146a62862c58b9dd9792 to your computer and use it in GitHub Desktop.
Save Alex1990/6cf23afd253b146a62862c58b9dd9792 to your computer and use it in GitHub Desktop.
Run eslint before `git commit` with npm scripts and `pre-commit` package.
{
"scripts": {
"lint-legacy": "files=$(git diff --cached --name-only | grep -v '.jsx$' | grep '.js$' | tr '\\n' ' '); if [[ -n \"$files\" ]]; then eslint --config ./.eslintrc.legacy.json --quiet $files || (git reset HEAD; exit 1); else exit 0; fi",
"lint-base": "files=$(git diff --cached --name-only | grep '.jsx$' | tr '\\n' ' '); if [[ -n \"$files\" ]]; then eslint --config ./.eslintrc.base.json --quiet $files || (git reset HEAD; exit 1); else exit 0; fi",
"lint": "npm run lint-legacy && npm run lint-base",
"lint-all": "(eslint --config ./.eslintrc.base.json --ext .jsx --quiet ./) && (eslint --config ./.eslintrc.legacy.json --ext .js --quiet ./)",
"build": "gulp build"
},
"pre-commit": [
"lint"
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment