nguyenvanduocit
7/30/2018 - 10:27 AM

Check for console.log before commit

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;