#!/bin/bash | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".*Marketplace.*\.js$") | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
PASS=true | |
eslint=$PWD/node_modules/.bin/eslint | |
phpcs=$PWD/vendor/bin/phpcs | |
if [ ! -f $eslint ]; then | |
printf "\n\033[41mPlease install ESlint\033[0m\n" | |
exit 1 | |
fi | |
if [ ! -f $phpcs ]; then | |
printf "\n\033[41mPlease install PHPCS\033[0m\n" | |
exit 1 | |
fi | |
printf "\nValidating Javascript:\n" | |
for FILE in $STAGED_FILES | |
do | |
$eslint "$FILE" | |
if [[ "$?" == 0 ]]; then | |
printf "\t\033[32mESLint Passed: $FILE\033[0m" | |
else | |
printf "\t\033[41mESLint Failed: $FILE\033[0m" | |
PASS=false | |
fi | |
done | |
if ! $PASS; then | |
printf "\n\033[41mCOMMIT FAILED:\033[0m" | |
printf " \033[00;33mYour commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\033[0m\n" | |
exit 1 | |
fi | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".*Marketplace.*\.php$") | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
printf "\nValidating PHPCS:\n" | |
for FILE in $STAGED_FILES | |
do | |
phpcs --standard=Config/phpcs/ruleset.xml "$FILE" | |
if [[ "$?" == 0 ]]; then | |
printf "\t\033[32mPHPCS Passed: $FILE\033[0m" | |
else | |
printf "\t\033[41mPHPCS Failed: $FILE\033[0m" | |
PASS=false | |
fi | |
done | |
if ! $PASS; then | |
printf "\n\033[41mCOMMIT FAILED:\033[0m" | |
printf " \033[00;33mYour commit contains files that should pass PHPCS but do not. Please fix the PHPCS errors and try again.\033[0m\n\n" | |
exit 1 | |
else | |
printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n\n" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment