Skip to content

Instantly share code, notes, and snippets.

@joshuacc
Created March 31, 2012 02:10
Show Gist options
  • Save joshuacc/2258630 to your computer and use it in GitHub Desktop.
Save joshuacc/2258630 to your computer and use it in GitHub Desktop.
isitgoodjs
#!/bin/bash
if [ "$1" == "" ]; then
echo -e "\e[00;32mPlease specify a JavaScript file to check."
exit 1
fi
git rev-parse --git-dir 1>/dev/null 2>&1
if [ $? != 0 ]; then
echo -e "\n\033[00;41;30mYou are not in a git repository.\033[00m\n"
exit 1
else
CONFIG=$(git rev-parse --git-dir)/hooks/jshint-config.json
if [ ! -e "$CONFIG" ]; then
echo -e "\n\033[00;41;30mThe JSHint config file is missing from your git repository.\033[00m\n"
exit 1
fi
fi
ERRORS=$(jshint $1 --config $(git rev-parse --git-dir)/hooks/jshint-config.json >&1)
if [ $? != 0 ]; then
if [ "$ERRORS_BUFFER" != "" ]; then
ERRORS_BUFFER="$ERRORS_BUFFER\n- $ERRORS"
else
ERRORS_BUFFER="- $ERRORS"
fi
echo "$ERRORS"
fi
if [ "$ERRORS_BUFFER" != "" ]; then
echo
echo -e "\033[00;41;30mNo good. :(\033[00m\n"
exit 1
else
echo -e "\n\033[00;42;30mAnd it was good. :)\033[00m\n"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment