Skip to content

Instantly share code, notes, and snippets.

@kailden
Created December 2, 2010 17:01
Show Gist options
  • Save kailden/725670 to your computer and use it in GitHub Desktop.
Save kailden/725670 to your computer and use it in GitHub Desktop.
Git pre commit hook for running jslint (installed as /usr/bin/jsl)
#!/bin/sh
# based on sample pre-commit hook distributed with git
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
skipjscheck=$(git config hooks.skipjscheck)
if [ "$skipjscheck" != "true" ]; then
for i in $(git diff-index --cached --full-index --name-only --diff-filter=ACMT -z $against); do
if jsl --nologo --nofilelisting --nosummary --conf=$HOME/.jslrc $i 2>&1 | grep "syntax_error"; then
echo "Error: Javascript files do not pass jsl error check"
exit 1;
else
if jsl --nologo --nofilelisting --nosummary --conf=$HOME/.jslrc $i 2>&1 | grep "undeclared identifier"; then
echo "Error: Undeclared javascript identifiers in $i"
exit 1;
else
echo "Javascript files ok."
fi
fi
done
fi
exec git diff-index --check --cached $against --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment