Skip to content

Instantly share code, notes, and snippets.

@letehaha
Last active October 21, 2020 09:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letehaha/6394089e96a581730c3f2391a9bc9002 to your computer and use it in GitHub Desktop.
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
# !/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