You can find csruleset.xml ar following link. https://gist.github.com/danyal14/3bb17a3a275314f39a7de60b47ae955b
Created
July 2, 2019 07:27
-
-
Save danyal14/720b46edff453a9dac19b846255e5d7a 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/sh | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".php\{0,1\}$") | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
PASS=true | |
echo "\nValidating PHPCS:\n" | |
# Check for phpcs | |
which ./vendor/bin/phpcs &> /dev/null | |
if [[ "$?" == 1 ]]; then | |
echo "\t\033[41mPlease install PHPCS\033[0m" | |
exit 1 | |
fi | |
RULESET=./csruleset.xml | |
for FILE in $STAGED_FILES | |
do | |
./vendor/bin/phpcs --standard="$RULESET" "$FILE" | |
if [[ "$?" == 0 ]]; then | |
echo "\t\033[32mPHPCS Passed: $FILE\033[0m" | |
else | |
echo "\t\033[41mPHPCS Failed: $FILE\033[0m" | |
PASS=false | |
fi | |
done | |
echo "\nPHPCS validation completed!\n" | |
if ! $PASS; then | |
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass PHPCS but do not. Please fix the PHPCS errors and try again.\n" | |
exit 1 | |
else | |
echo "\033[42mCOMMIT SUCCEEDED\033[0m\n" | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment