Last active
October 21, 2020 09:22
-
-
Save letehaha/6394089e96a581730c3f2391a9bc9002 to your computer and use it in GitHub Desktop.
Checks eslint errors/warnings in pre-commit hook. Disable commit if errors found
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 | |
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E "(.js|.vue)$") | |
if [ "$files" == "" ]; then | |
exit 0 | |
fi | |
lintfiles="" | |
errors="false" | |
for file in ${files}; do | |
if [[ $file != *".eslintrc.js"* ]]; then | |
./node_modules/.bin/eslint --max-warnings 0 $file | |
if [[ $? -ne 0 ]]; then | |
lintfiles+="\n$file" | |
errors="true" | |
fi | |
fi | |
done | |
if [ "$errors" == "true" ]; then | |
echo "\n\033[41m COMMIT FAILED: \033[0m Your commit contains lint errors and/or warnings. Fix it before push" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment