Skip to content

Instantly share code, notes, and snippets.

@nguyenvanduocit
Created July 30, 2018 10:27
Show Gist options
  • Save nguyenvanduocit/38829b8ed727605582bbca546b2fe184 to your computer and use it in GitHub Desktop.
Save nguyenvanduocit/38829b8ed727605582bbca546b2fe184 to your computer and use it in GitHub Desktop.
Check for console.log before commit
#!/bin/sh
# 5:23 PM Friday, October 18, 2013 - Jim Priest
# origin script found here: http://python.dzone.com/articles/tips-using-git-pre-commit-hook
# Modified with console checks and to ignore commented file
echo "Executing post-commit checks..."
FILES_PATTERN='\.(js)(\..+)?$'
FORBIDDEN='console\.[clear|dir|log|info|warn|error]'
if git diff --cached --name-only | \
grep -E $FILES_PATTERN | \
xargs grep --with-filename -n $FORBIDDEN | \
grep -v '//';
then
echo 'COMMIT REJECTED! Found console. references. Please remove them before committing.'
exit 1;
fi
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment