Created
October 20, 2015 14:45
-
-
Save eseceve/0643e1126a31c3bdb9be to your computer and use it in GitHub Desktop.
Git pre-commit hook to run ESlint
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 | |
STAGED_FILES=$(git diff --cached --name-only --dif-filter=ACM | grep ".jsx\{0,1\}$") | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
PASS=true | |
echo "Validating Javascript:" | |
# Check for eslint | |
which eslint &> /dev/null | |
if [[ "$?" == 1 ]]; then | |
echo "Please install ESlint" | |
exit 1 | |
fi | |
for FILE in $STAGED_FILES | |
do | |
eslint "$FILE" | |
if [[ "$?" == 0 ]]; then | |
echo "ESlint passed: $FILE" | |
else | |
echo "$?" | |
PASS=false | |
fi | |
done | |
echo "Javascript validation completed!" | |
if ! $PASS; then | |
echo "Commmit failed: your commit contains files that should pass ESlint but do not" | |
exit 1 | |
else | |
echo "Commit succeeded" | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment