Skip to content

Instantly share code, notes, and snippets.

@odracci
Created November 11, 2011 22:33
Show Gist options
  • Save odracci/1359528 to your computer and use it in GitHub Desktop.
Save odracci/1359528 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Pre-commit hook passing files through jslint
#
# This ensures that all js, html and json files are valid and conform
# to expectations.
ROOT_DIR=$(git rev-parse --show-toplevel)
JSLINT="${ROOT_DIR}/node_modules/.bin/jslint --indent 4 --white true"
for file in $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P '\.((js)|(html)|(json))$'); do
if node $JSLINT $file 2>&1 | grep 'No errors found' ; then
echo "jslint passed ${file}"
exit 0
else
node $JSLINT $file
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment