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 '(\