I recently started a project on github. I\'ve managed to setup automatic testing after each commit using Travis. But now I would like to setup a pre-commit hook with jshint
Some changes to @James Allardice script to accommodate JSHint. Thanks for the original code.
#!/bin/sh
#
# Run JSHint validation before commit.
files=$(git diff --cached --name-only --diff-filter=ACMR -- *.js **/*.js)
pass=true
if [ "$files" != "" ]; then
for file in ${files}; do
result=$(jshint ${file})
if [ "$result" != "" ]; then
echo "$result"
echo "\n"
pass=false
fi
done
fi
if $pass; then
exit 0
else
echo ""
echo "COMMIT FAILED:"
echo "Some JavaScript files are invalid. Please fix errors and try committing again."
exit 1
fi