Skip to content

Instantly share code, notes, and snippets.

@rgruesbeck
Last active June 5, 2019 17:53
Show Gist options
  • Save rgruesbeck/afb23d9179223a6ef777296547061212 to your computer and use it in GitHub Desktop.
Save rgruesbeck/afb23d9179223a6ef777296547061212 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".js\{0,1\}$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
printf "\nValidating Javascript:\n"
# Check for eslint
which eslint &> /dev/null
if [[ "$?" == 1 ]]; then
printf "${RED}Please install ESlint\n"
exit 1
fi
for FILE in $STAGED_FILES
do
eslint "$FILE"
if [[ "$?" == 0 ]]; then
printf "${GREEN}ESLint Passed:${NC} $FILE\n"
else
printf "${RED}ESLint Failed:${NC} $FILE\n"
PASS=false
fi
done
printf "\nJavascript validation completed!\n"
if ! $PASS; then
printf "${RED}COMMIT FAILED:${NC} Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n"
exit 1
else
printf "${GREEN}COMMIT SUCCEEDED${NC}\n"
fi
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment