Created
November 12, 2020 16:54
-
-
Save andrewdieken/b06c0bd851921f2aa1622c6004742bc4 to your computer and use it in GitHub Desktop.
pre-commit hook for JavaScript projects
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 | |
# Redirect output to stderr. | |
exec 1>&2 | |
is_commit_clean=true | |
# invalid strings | |
consoleregexp='^\+.*console\.log\|fdescribe\|debugger' | |
# list all the files staged for commit | |
files_changed=$(git diff --cached --name-only 2>&1) | |
for file in $files_changed | |
do | |
if git diff --cached $file | grep $consoleregexp >/dev/null; then | |
echo "* $file" | |
is_commit_clean=false | |
fi | |
done | |
if [ $is_commit_clean == false ]; then | |
echo "" | |
echo "Errors, aborting. Ensure the following statements are removed from the files above before commiting" | |
echo "**** console.log ****" | |
echo "**** fdescribe ****" | |
echo "**** debugger ****" | |
exit 1 | |
else | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment