Created
July 12, 2013 18:17
-
-
Save arashm/5986588 to your computer and use it in GitHub Desktop.
If you want to make sure that all of your JS code stays compliant to the style defined in your .jshintrc, you can set the following contents to your .git/hooks/pre-commit file, which is then run each time you try to commit any new of modified files to the project
http://seravo.fi/2013/javascript-the-winning-style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Pre-commit Git hook to run JSHint on JavaScript files. | |
# | |
# If you absolutely must commit without testing, | |
# use: git commit --no-verify | |
filenames=($(git diff --cached --name-only HEAD)) | |
which jshint &> /dev/null | |
if [ $? -ne 0 ]; | |
then | |
echo "error: jshint not found" | |
echo "install with: sudo npm install -g jshint" | |
exit 1 | |
fi | |
for i in "${filenames[@]}" | |
do | |
if [[ $i =~ \.js$ ]]; | |
then | |
echo jshint $i | |
jshint $i | |
if [ $? -ne 0 ]; | |
then | |
exit 1 | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment