Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- export PATH=/usr/local/bin:$PATH
- files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
- pass=true
- if [ "$files" = "" ]; then
- exit 0
- fi
- pass=true
- echo "\nValidating JavaScript:\n----------------------"
- for file in ${files}; do
- resultLint=$(/usr/local/bin/jshint $PWD/${file} | grep "error")
- resultCS=$(/usr/local/bin/jscs $PWD/${file} | grep "style errors found")
- errorsLint=$(/usr/local/bin/jshint $PWD/${file})
- errorsCS=$(/usr/local/bin/jscs $PWD/${file})
- if [ "$resultLint" == "" ]; then
- echo "JSHint Passed: ${file}"
- else
- echo "$errorsLint"
- echo "JSHint Failed: ${file}"
- pass=false
- fi
- if [ "$resultCS" == "" ]; then
- echo "JSCS Passed: ${file}"
- else
- echo "$errorsCS"
- echo "JSCS Failed: ${file}"
- pass=false
- fi
- if [ "$file" == ".jscsrc" ]; then
- echo "You are not allowed to modifly .jscsrc"
- pass=false
- fi
- if [ "$file" == ".jshintrc" ]; then
- echo "You are not allowed to modifly .jscsrc"
- pass=false
- fi
- done
- echo "\nJavaScript validation complete\n"
- if ! $pass; then
- echo "COMMIT FAILED: Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again.\n"
- exit 1
- else
- echo "COMMIT SUCCEEDED"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement