scripts/commit-code-check.sh | 72 +++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/scripts/commit-code-check.sh b/scripts/commit-code-check.sh index 2f4eeecb..ef306a4d 100755 --- a/scripts/commit-code-check.sh +++ b/scripts/commit-code-check.sh @@ -69,63 +69,44 @@ fi # run and all dependencies are updated. FINAL_STATUS=0 -separator() { +print_separator() { printf "\n${title}" printf -- '-%.0s' {1..100} printf "${reset}\n" } +print_title() { + print_separator + printf "${title}$1${reset}" + print_separator +} +print_results() { + RESULTS=$1 + LABEL=$2 + if [ "$RESULTS" -ne "0" ]; then + # If there are failures set the status to a number other than 0. + FINAL_STATUS=1 + printf "\n${title}$LABEL: ${red}failed${reset}\n" + else + printf "\n${title}$LABEL: ${green}passed${reset}\n" + fi +} - -# -# phpcs -# -printf "\n${title}[1/4] PHPCS${reset}\n" +print_title "[1/4] PHPCS" $CORE_DIRECTORY/vendor/bin/phpcs $MODULE_DIRECTORY -ps --standard="$CORE_DIRECTORY/core/phpcs.xml.dist" -PHPCS=$? -if [ "$PHPCS" -ne "0" ]; then - # If there are failures set the status to a number other than 0. - FINAL_STATUS=1 - printf "\n${title}PHPCS: ${red}failed${reset}\n" -else - printf "\n${title}PHPCS: ${green}passed${reset}\n" -fi +print_results $? "PHPCS" -separator - -# phpstan -printf "\n${title}[2/4] PHPStan${reset}\n" +print_title "[2/4] PHPStan" php -d apc.enabled=0 -d apc.enable_cli=0 $CORE_DIRECTORY/vendor/bin/phpstan analyze --no-progress --configuration="$CORE_DIRECTORY/core/phpstan.neon.dist" $MODULE_DIRECTORY -if [ "$?" -ne "0" ]; then - # If there are failures set the status to a number other than 0. - FINAL_STATUS=1 - printf "\n${title}PHPStan: ${red}failed${reset}\n" -else - printf "\n${title}PHPStan: ${green}passed${reset}\n" -fi - -separator +print_results $? "PHPStan" -## cspell -printf "\n${title}[3/4] CSpell${reset}\n" +print_title "[3/4] CSpell" cd $CORE_DIRECTORY/core && yarn run -s spellcheck --no-progress --root $MODULE_DIRECTORY -c .cspell.json "**" && cd - -if [ "$?" -ne "0" ]; then - # If there are failures set the status to a number other than 0. - FINAL_STATUS=1 - printf "\n${title}CSpell: ${red}failed${reset}\n" -else - printf "\n${title}CSpell: ${green}passed${reset}\n" -fi +print_results $? "CSpell" -# eslint YAML files -printf "\n${title}[4/4] lint:yaml${reset}\n" +print_title "[4/4] eslint:yaml" cd $CORE_DIRECTORY/core && yarn eslint --resolve-plugins-relative-to . --ext .yml $MODULE_DIRECTORY && cd - -if [ "$?" -ne "0" ]; then - # If there are failures set the status to a number other than 0. - FINAL_STATUS=1 - printf "\n${title}lint:yaml: ${red}failed${reset}\n" -else - printf "\n${title}lint:yaml: ${green}passed${reset}\n" -fi +print_results $? "eslint:yaml" +print_separator if [[ "$FINAL_STATUS" == "1" ]]; then printf "${red}Drupal code quality checks failed.${reset}" @@ -134,5 +115,6 @@ if [[ "$FINAL_STATUS" == "1" ]]; then printf "* Apply the change as a patch, or from the merge request branch\n" printf "* Run this command locally: sh ./scripts/commit-code-check.sh" fi + print_separator fi exit $FINAL_STATUS