#!/bin/sh files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$") if [ "$files" = "" ]; then exit 0 fi pass=true echo "nValidating JavaScript:n" for file in ${files}; do result=$(jslint ${file} | grep "${file} is OK") if [ "$result" != "" ]; then echo "t33[32mJSLint Passed: ${file}33[0m" else echo "t33[31mJSLint Failed: ${file}33[0m" pass=false fi done echo "nJavaScript validation completen" if ! $pass; then echo "33[41mCOMMIT FAILED:33[0m Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again.n" exit 1 else echo "33[42mCOMMIT SUCCEEDED33[0mn" fi #!/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 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