Created
July 10, 2018 09:49
-
-
Save dsheiko/6200f2c145b548559e3b6f6722aac0fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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