From de4e53f94112f5d74e4f15267d903133bb2e10d5 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Fri, 16 Apr 2021 01:29:27 +0100 Subject: [PATCH] build: add PHPCompat checks to pre-commit hook --- contrib/pre-commit | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/contrib/pre-commit b/contrib/pre-commit index 0dc792f..f4b5861 100644 --- a/contrib/pre-commit +++ b/contrib/pre-commit @@ -29,33 +29,36 @@ do FILES="$FILES $PROJECT/$FILE" done -if [ -f "$PROJECT/phpcs.ruleset.xml" ] -then - RULESET="$PROJECT/phpcs.ruleset.xml" -elif [ -f "$PROJECT/phpcs.xml.dist" ] -then - RULESET="$PROJECT/phpcs.xml.dist" -else - RULESET="WordPress" -fi +#if [ -f "$PROJECT/phpcs.ruleset.xml" ] +#then +# RULESET="$PROJECT/phpcs.ruleset.xml" +#elif [ -f "$PROJECT/phpcs.xml.dist" ] +#then +# RULESET="$PROJECT/phpcs.xml.dist" +#else + RULESETS=["WordPress","PHPCompatibilityWP"] +#fi if [ "$FILES" != "" ] then - echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..." - ./vendor/bin/phpcs --standard="$RULESET" --colors --encoding=utf-8 -n -p $FILES - if [ $? != 0 ] - then - echo "Coding standards errors have been detected. Running phpcbf..." - ./vendor/bin/phpcbf --standard="$RULESET" --encoding=utf-8 -n -p $FILES - git add $FILES - echo "Running Code Sniffer again..." - ./vendor/bin/phpcs --standard="$RULESET" --colors --encoding=utf-8 -n -p $FILES + for RULESET in $RULESETS; do + echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..." + ./vendor/bin/phpcs --standard="$RULESET" --runtime-set testVersion 7.0- --colors --encoding=utf-8 -n -p $FILES if [ $? != 0 ] then - echo "Errors found not fixable automatically. You need to manually fix them." - exit 1 + echo "Coding standards errors have been detected. Running phpcbf..." + ./vendor/bin/phpcbf --standard="$RULESET" --runtime-set testVersion 7.0- --encoding=utf-8 -n -p $FILES + git add $FILES + echo "Running Code Sniffer again..." + ./vendor/bin/phpcs --standard="$RULESET" --runtime-set testVersion 7.0- --colors --encoding=utf-8 -n -p $FILES + if [ $? != 0 ] + then + echo "Errors found not fixable automatically. You need to manually fix them." + exit 1 + fi fi - fi + echo "$RULESET passed." + done fi exit $?