Skip to content

Instantly share code, notes, and snippets.

@DanieleSalatti
Created September 23, 2022 13:45
Show Gist options
  • Save DanieleSalatti/13b2a516ee499bb701ee90a67ab8a553 to your computer and use it in GitHub Desktop.
Save DanieleSalatti/13b2a516ee499bb701ee90a67ab8a553 to your computer and use it in GitHub Desktop.
pre-commit git hook to check for leftover console.log(s)
#!/bin/sh
exec 1>&2
exec < /dev/tty
consoleregexp='^\+.*console\.log('
if test $(git diff --cached -U0 | grep $consoleregexp | wc -l) != 0
then
exec git diff --cached | grep -ne $consoleregexp
read -p "It looks like you have left some console.log statements in your code. Are you sure want to continue? (y/n)" yn
echo $yn | grep ^[Yy]$
if [ $? -eq 0 ]
then
exit 0;
else
exit 1;
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment