Skip to content

Instantly share code, notes, and snippets.

@dsheiko
Created July 10, 2018 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsheiko/6200f2c145b548559e3b6f6722aac0fb to your computer and use it in GitHub Desktop.
Save dsheiko/6200f2c145b548559e3b6f6722aac0fb to your computer and use it in GitHub Desktop.
#!/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