Last active
June 14, 2017 05:03
-
-
Save ekoneko/fb4024c615cea9c586a16f79b12f23ab to your computer and use it in GitHub Desktop.
ESLint Pre Commit Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ESLint Pre Commit Check | |
# put to `.git/hooks/pre-commit` | |
eslint_check() { | |
files=$(git diff --cached --name-only --diff-filter=AM | grep '\.jsx\?$') | |
if [[ $files = "" ]] ; then | |
return | |
fi | |
failed=0 | |
for file in ${files}; do | |
git show :$file | ./node_modules/eslint/bin/eslint.js $file | |
if [[ $? != 0 ]] ; then | |
failed=1 | |
fi | |
done; | |
if [[ $failed != 0 ]] ; then | |
echo "🚫 ESLint failed, git commit denied!" | |
exit $failed | |
fi | |
} | |
eslint_check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment