-
-
Save hamidzr/d5095c5d27ed8730809647c39962459f to your computer and use it in GitHub Desktop.
Pre-commit hook to check for Javascript using 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/bash | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$") | |
# def colors | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
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 "$GREEN ESLint Passed: $FILE $NC" | |
# else | |
# echo -e "$RED ESLint Failed: $FILE $NC" | |
PASS=false | |
fi | |
done | |
# echo "Javascript validation completed!" | |
if ! $PASS; then | |
echo -e "$RED COMMIT ABORTED $NC" | |
exit 1 | |
# else | |
# echo "$GREEN COMMIT SUCCEEDED $NC" | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy/append to .git/hooks/pre-commit