Last active
May 30, 2016 07:26
-
-
Save thesabbir/a62e1a1b11a05974d78f256e67873932 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"precommit.silent": true, | |
"pre-commit": [ | |
"pre-commit-eslint" | |
] |
This file contains hidden or 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 --diff-filter=ACM | grep ".jsx\{0,1\}$") | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
PASS=true | |
echo "Running ESLint validation:\n" | |
for FILE in $STAGED_FILES | |
do | |
`npm bin`/eslint "$FILE" | |
if [[ "$?" == 0 ]]; then | |
echo "\n\033[32mESLint validation passed!: $FILE\033[0m" | |
else | |
echo "\n\033[31mValidation failed --> $FILE\033[0m" | |
PASS=false | |
fi | |
done | |
echo "\nCheck completed!\n" | |
if ! $PASS; then | |
echo "\n\033[31mCOMMIT FAILED: YOU SHALL NOT PASS!!\033[0m" | |
echo "\n\033[36mPlease fix ESLint error[s] and retry!\033[0m" | |
exit 1 | |
else | |
echo "\n\033[32mCOMMIT SUCCEEDED\033[0m\n" | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment