Last active
November 16, 2022 19:35
-
-
Save Kmaschta/98a508a43f902628209e57a06f73f88e to your computer and use it in GitHub Desktop.
Pre-commit hook (warn if you have it.only, describe.only, fit or fdescribe)
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/bash | |
SRC=$(git rev-parse --show-toplevel) | |
EXCLUDE="--exclude-dir 'node_modules' --exclude-dir '.git'" | |
#========================================================== | |
# Check if I forgot to remove 'only' keyword from tests. | |
# To make sure that before commit run all tests | |
only_command="grep -c -h -r $EXCLUDE -E \"(describe|it)\.only\" $SRC | awk -F ':' '{x +=\$0}; END {print x}'" | |
fonly_command="grep -c -h -r $EXCLUDE -E \"f(it|describe)\(\" $SRC | awk -F ':' '{x +=\$0}; END {print x}'" | |
only=`eval $only_command` | |
fonly=`eval $fonly_command` | |
if (( $((only + fonly)) > 0 )) | |
then | |
echo 'Remove ONLY from tests.' | |
# Output list of found only entries | |
eval "grep -r -n $EXCLUDE -E \"(describe|it)\.only\" $SRC" | |
eval "grep -r -n $EXCLUDE -E \"f(it|describe)\(\" $SRC" | |
exit 1 | |
fi |
Why not limit the grep to what is being commited (or rather the "add" part of the commit)?
Because I didn't know how to that before I've read your code.
Your Junk Checker is definitely better than my little script! But it does the job without install a plugin.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install it and do not forget execution permisions.
curl https://gist.githubusercontent.com/Kmaschta/98a508a43f902628209e57a06f73f88e/raw/pre-commit > .git/hooks/pre-commit chmod +x .git/hooks/pre-commit