From c72fbad90d34f090ac9ac13c91f14af2ee979ce3 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 22 Sep 2018 14:38:30 +0200 Subject: [PATCH] Try fixing hook script --- Hooks/delegator.sh | 15 ++++++++------- Hooks/filename.sh | 2 ++ Hooks/logging.sh | 4 ++++ Hooks/syntax.sh | 17 +++++++++++++++++ Hooks/tests.sh | 4 ++++ Hooks/travis.sh | 11 ++++------- 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Hooks/delegator.sh b/Hooks/delegator.sh index 776ae40..8f15041 100644 --- a/Hooks/delegator.sh +++ b/Hooks/delegator.sh @@ -1,17 +1,21 @@ #!/bin/bash +set -x + . ${rootpath}/Build/Hooks/logging.sh . ${rootpath}/Build/Hooks/syntax.sh . ${rootpath}/Build/Hooks/filename.sh . ${rootpath}/Build/Hooks/tests.sh git diff --cached --name-only | while read FILE; do + echo $FILE + if [[ ! -f "$FILE" ]]; then continue fi # Filename - if [[ $(isValidFileName "$FILE") = 1 ]]; then + if [[ $(isValidFileName "$FILE") = 0 ]]; then echo -e "\e[1;31m\tInvalid file name '$FILE'.\e[0m" >&2 exit 1 fi @@ -38,8 +42,7 @@ git diff --cached --name-only | while read FILE; do # Syntax if [[ "$FILE" =~ ^.+(php)$ ]]; then - $(hasInvalidPhpSyntax "$FILE") - PHP_SYNTAX=$? + PHP_SYNTAX=$(hasInvalidPhpSyntax "$FILE") if [[ $PHP_SYNTAX = 1 ]]; then echo -e "\e[1;31m\tPhp linting error.\e[0m" >&2 @@ -63,8 +66,7 @@ git diff --cached --name-only | while read FILE; do fi if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then - $(hasInvalidBasicSyntax "$FILE") - GEN_SYNTAX=$? + GEN_SYNTAX=$(hasInvalidBasicSyntax "$FILE") if [[ $GEN_SYNTAX = 1 ]]; then echo -e "\e[1;31m\tFound whitespace at end of line in $FILE.\e[0m" >&2 @@ -80,8 +82,7 @@ git diff --cached --name-only | while read FILE; do fi if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then - $(hasInvalidHtmlTemplateContent "$FILE") - TPL_SYNTAX=$? + TPL_SYNTAX=$(hasInvalidHtmlTemplateContent "$FILE") if [[ $TPL_SYNTAX = 1 ]]; then echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2 diff --git a/Hooks/filename.sh b/Hooks/filename.sh index a411dac..a657580 100644 --- a/Hooks/filename.sh +++ b/Hooks/filename.sh @@ -4,8 +4,10 @@ isValidFileName() { if test $(git diff --cached --name-only --diff-filter=A -z "$1" | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 then + echo 0 return 0 fi + echo 1 return 1 } \ No newline at end of file diff --git a/Hooks/logging.sh b/Hooks/logging.sh index 05f2e8f..952efa2 100644 --- a/Hooks/logging.sh +++ b/Hooks/logging.sh @@ -3,17 +3,21 @@ hasPhpLogging() { RESULT=$(grep "var_dump(" "$1") if [ ! -z $RESULT ]; then + echo 1 return 1 fi + echo 0 return 0 } hasJsLogging() { RESULT=$(grep " console.log(" "$1") if [ ! -z $RESULT ]; then + echo 1 return 1 fi + echo 0 return 0 } \ No newline at end of file diff --git a/Hooks/syntax.sh b/Hooks/syntax.sh index f2f4a2d..62cbdf9 100644 --- a/Hooks/syntax.sh +++ b/Hooks/syntax.sh @@ -4,82 +4,99 @@ hasInvalidPhpSyntax() { # php lint $(php -l "$1" > /dev/null) if [[ $? != 0 ]]; then + echo 1 return 1 fi # phpcs $(php -d memory_limit=4G ${rootpath}/vendor/bin/phpcs --standard="${rootpath}/Build/Config/phpcs.xml" --encoding=utf-8 -n -p "$1" > /dev/null) if [[ $? != 0 ]]; then + echo 2 return 2 fi # phpmd $(php -d memory_limit=4G ${rootpath}/vendor/bin/phpmd "$1" text ${rootpath}/Build/Config/phpmd.xml --exclude *tests* --minimumpriority 1 > /dev/null) if [[ $? != 0 ]]; then + echo 3 return 3 fi + echo 0 return 0 } hasInvalidHtmlTemplateContent() { # Images must have a alt= attribute *error* if [[ -n $(grep -P '(\)' "$1") ]]; then + echo 1 return 1 fi # Input elements must have a type= attribute *error* if [[ -n $(grep -P '()' "$1") ]]; then + echo 2 return 2 fi # Form fields must have a name *error* if [[ -n $(grep -P '()' "$1") ]]; then + echo 3 return 3 fi # Form must have a id, action and method *error* if [[ -n $(grep -P '(\)' "$1") ]]; then + echo 4 return 4 fi # Inline css is invalid *warning* if [[ -n $(grep -P '(style=)' "$1") ]]; then + echo 5 return 5 fi # Attribute descriptions should not be hard coded *warning* if [[ -n $(grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' "$1") ]]; then + echo 6 return 6 fi # Hard coded language *warning* if [[ -n $(grep -P '(\|\|\|\)[0-9a-zA-Z\.\?]+' "$1") ]]; then + echo 7 return 7 fi + echo 0 return 0 } isValidBashScript() { bash -n "$1" 1> /dev/null if [ $? -ne 0 ]; then + echo 0 return 0 fi + echo 1 return 1 } hasInvalidBasicSyntax() { # Check whitespace end of line in code if [[ -n $(grep -P ' $' "$1") ]]; then + echo 1 return 1 fi # Check for tabs if [[ -n $(grep -P '\t' "$1") ]]; then + echo 2 return 2 fi + echo 0 return 0 } \ No newline at end of file diff --git a/Hooks/tests.sh b/Hooks/tests.sh index 8285411..120e01c 100644 --- a/Hooks/tests.sh +++ b/Hooks/tests.sh @@ -3,17 +3,21 @@ isPhanTestSuccessful() { php -d memory_limit=4G ${rootpath}/vendor/bin/phan -k ${rootpath}/Build/Config/phan.php -f "$1" >&2 if [ $? -ne 0 ]; then + echo 0 return 0 fi + echo 1 return 1 } isPhpStanTestSuccessful() { php -d memory_limit=4G ${rootpath}/vendor/bin/phpstan analyse --autoload-file=${rootpath}/phpOMS/Autoloader.php -l 7 -c ${rootpath}/Build/Config/phpstan.neon "$1" >&2 if [ $? -ne 0 ]; then + echo 0 return 0 fi + echo 1 return 1 } \ No newline at end of file diff --git a/Hooks/travis.sh b/Hooks/travis.sh index e9fd2d6..eb82673 100644 --- a/Hooks/travis.sh +++ b/Hooks/travis.sh @@ -13,7 +13,7 @@ git diff --name-only $TRAVIS_COMMIT_RANGE | while read FILE; do fi # Filename - if [[ $(isValidFileName "$FILE") = 1 ]]; then + if [[ $(isValidFileName "$FILE") = 0 ]]; then echo -e "\e[1;31m\tInvalid file name '$FILE'.\e[0m" >&2 exit 1 fi @@ -40,8 +40,7 @@ git diff --name-only $TRAVIS_COMMIT_RANGE | while read FILE; do # Syntax if [[ "$FILE" =~ ^.+(php)$ ]]; then - $(hasInvalidPhpSyntax "$FILE") - PHP_SYNTAX=$? + PHP_SYNTAX=$(hasInvalidPhpSyntax "$FILE") if [[ $PHP_SYNTAX = 1 ]]; then echo -e "\e[1;31m\tPhp linting error.\e[0m" >&2 @@ -65,8 +64,7 @@ git diff --name-only $TRAVIS_COMMIT_RANGE | while read FILE; do fi if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then - $(hasInvalidBasicSyntax "$FILE") - GEN_SYNTAX=$? + GEN_SYNTAX=$(hasInvalidBasicSyntax "$FILE") if [[ $GEN_SYNTAX = 1 ]]; then echo -e "\e[1;31m\tFound whitespace at end of line in $FILE.\e[0m" >&2 @@ -82,8 +80,7 @@ git diff --name-only $TRAVIS_COMMIT_RANGE | while read FILE; do fi if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then - $(hasInvalidHtmlTemplateContent "$FILE") - TPL_SYNTAX=$? + TPL_SYNTAX=$(hasInvalidHtmlTemplateContent "$FILE") if [[ $TPL_SYNTAX = 1 ]]; then echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2