Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- STAGED_FILES=$(git diff --staged --name-only | grep -E '\.(js|jsx)$')
- ESLINT="$(git rev-parse --show-toplevel)/gabi-react/node_modules/.bin/eslint"
- if [[ "$STAGED_FILES" = "" ]]; then
- exit 0
- fi
- PASS=true
- echo "Validating Javascript:"
- # Check for eslint
- if [[ ! -x "$ESLINT" ]]; then
- printf "Please install ESlint (npm i --save-dev eslint)"
- exit 1
- fi
- for FILE in $STAGED_FILES
- do
- "$ESLINT" "$FILE" --fix
- if [[ "$?" == 0 ]]; then
- printf "ESLint Passed: $FILE"
- else
- printf "ESLint Failed: $FILE"
- PASS=false
- fi
- done
- printf "Javascript validation completed!"
- if ! $PASS; then
- printf "COMMIT FAILED: Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again."
- exit 1
- else
- printf "COMMIT SUCCEEDED"
- fi
- exit $?
Add Comment
Please, Sign In to add comment