Guest User

Untitled

a guest
May 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. STAGED_FILES=$(git diff --staged --name-only | grep -E '\.(js|jsx)$')
  4. ESLINT="$(git rev-parse --show-toplevel)/gabi-react/node_modules/.bin/eslint"
  5.  
  6. if [[ "$STAGED_FILES" = "" ]]; then
  7. exit 0
  8. fi
  9.  
  10. PASS=true
  11.  
  12. echo "Validating Javascript:"
  13.  
  14. # Check for eslint
  15. if [[ ! -x "$ESLINT" ]]; then
  16. printf "Please install ESlint (npm i --save-dev eslint)"
  17. exit 1
  18. fi
  19.  
  20. for FILE in $STAGED_FILES
  21. do
  22. "$ESLINT" "$FILE" --fix
  23.  
  24. if [[ "$?" == 0 ]]; then
  25. printf "ESLint Passed: $FILE"
  26. else
  27. printf "ESLint Failed: $FILE"
  28. PASS=false
  29. fi
  30. done
  31.  
  32. printf "Javascript validation completed!"
  33.  
  34. if ! $PASS; then
  35. printf "COMMIT FAILED: Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again."
  36. exit 1
  37. else
  38. printf "COMMIT SUCCEEDED"
  39. fi
  40.  
  41. exit $?
Add Comment
Please, Sign In to add comment