Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/bin/sh
  2. export PATH=/usr/local/bin:$PATH
  3.  
  4. files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
  5. pass=true
  6.  
  7. if [ "$files" = "" ]; then
  8. exit 0
  9. fi
  10.  
  11. pass=true
  12.  
  13. echo "\nValidating JavaScript:\n----------------------"
  14.  
  15. for file in ${files}; do
  16.  
  17. resultLint=$(/usr/local/bin/jshint $PWD/${file} | grep "error")
  18. resultCS=$(/usr/local/bin/jscs $PWD/${file} | grep "style errors found")
  19. errorsLint=$(/usr/local/bin/jshint $PWD/${file})
  20. errorsCS=$(/usr/local/bin/jscs $PWD/${file})
  21.  
  22. if [ "$resultLint" == "" ]; then
  23. echo "JSHint Passed: ${file}"
  24. else
  25. echo "$errorsLint"
  26. echo "JSHint Failed: ${file}"
  27. pass=false
  28. fi
  29.  
  30. if [ "$resultCS" == "" ]; then
  31. echo "JSCS Passed: ${file}"
  32. else
  33. echo "$errorsCS"
  34. echo "JSCS Failed: ${file}"
  35. pass=false
  36. fi
  37.  
  38. if [ "$file" == ".jscsrc" ]; then
  39. echo "You are not allowed to modifly .jscsrc"
  40. pass=false
  41. fi
  42.  
  43. if [ "$file" == ".jshintrc" ]; then
  44. echo "You are not allowed to modifly .jscsrc"
  45. pass=false
  46. fi
  47.  
  48. done
  49.  
  50. echo "\nJavaScript validation complete\n"
  51.  
  52. if ! $pass; then
  53. echo "COMMIT FAILED: Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again.\n"
  54. exit 1
  55. else
  56. echo "COMMIT SUCCEEDED"
  57. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement