Last active
August 29, 2015 14:09
-
-
Save techird/0104a1dd01c2d19919c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# @Author: techird | |
# @Date: 2014/11/19 11:10 | |
# @Last Modified by: techird | |
# @Last Modified time: 2014/11/19 11:10 | |
#git diff --cached --name-only --diff-filter=ACMR | |
files=$(git diff --cached --name-only --diff-filter=ACMR | grep "\.js$") | |
if [ "$files" = "" ]; then | |
exit 0 | |
fi | |
pass=true | |
echo "\nValidating JavaScript...\n" | |
for file in ${files}; do | |
result=$( (jshint --verbose ${file} && jscs ${file}) | grep -o 'line\s\d*.*$' ) | |
if [ "$result" == "" ]; then | |
echo " \033[32mPass: ${file}\033[0m" | |
else | |
echo " \033[31mFail: ${file}\033[0m" | |
echo "$(echo "$result" | grep -o 'line\s\d*.*$' | sed s/^/\ \ \ \ \>\ /g)\n" | |
pass=false | |
fi | |
done | |
echo "\nJavaScript validation complete\n" | |
if ! $pass; then | |
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSHint and JSCS but do not. Please fix the the errors and try again.\n" | |
exit 1 | |
else | |
echo "\033[32mCOMMIT SUCCEEDED\033[0m\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment