Skip to content

Instantly share code, notes, and snippets.

@winkerVSbecks
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save winkerVSbecks/73b3dfda4c3a17bf76c2 to your computer and use it in GitHub Desktop.

Select an option

Save winkerVSbecks/73b3dfda4c3a17bf76c2 to your computer and use it in GitHub Desktop.
Run JSHint validation before commit
#!/bin/bash
#
# Run JSHint validation before commit.
files=$(git diff --cached --name-only --diff-filter=ACM | grep '.js$')
pass=true
# JSHint
if [ "$files" != "" ]; then
for file in ${files}; do
jshint ${file}
if [[ $? -ne 0 ]]; then
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment