Skip to content

Instantly share code, notes, and snippets.

@frnkst
Created March 19, 2018 15:34
Show Gist options
  • Save frnkst/516610358a105d57291aa1644d8db2be to your computer and use it in GitHub Desktop.
Save frnkst/516610358a105d57291aa1644d8db2be to your computer and use it in GitHub Desktop.
Run eslint on all staged files before committing
#!/bin/bash
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.js$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again."
exit 1 # exit with failure status
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment