Skip to content

Instantly share code, notes, and snippets.

@thesabbir
Last active May 30, 2016 07:26
Show Gist options
  • Save thesabbir/a62e1a1b11a05974d78f256e67873932 to your computer and use it in GitHub Desktop.
Save thesabbir/a62e1a1b11a05974d78f256e67873932 to your computer and use it in GitHub Desktop.
"precommit.silent": true,
"pre-commit": [
"pre-commit-eslint"
]
#!/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