mirror of
https://github.com/Karaka-Management/Build.git
synced 2026-05-26 05:28:39 +00:00
Create travis build+pull out to functions
This commit is contained in:
parent
3cd6b6af54
commit
8443c22066
|
|
@ -1,12 +1,124 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
|
||||||
if [[ ! -f "$FILE" ]]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
. ${rootpath}/Build/Hooks/logging.sh
|
. ${rootpath}/Build/Hooks/logging.sh
|
||||||
. ${rootpath}/Build/Hooks/syntax.sh
|
. ${rootpath}/Build/Hooks/syntax.sh
|
||||||
. ${rootpath}/Build/Hooks/filename.sh
|
. ${rootpath}/Build/Hooks/filename.sh
|
||||||
. ${rootpath}/Build/Hooks/tests.sh
|
. ${rootpath}/Build/Hooks/tests.sh
|
||||||
|
|
||||||
|
git diff --cached --name-only | while read FILE; do
|
||||||
|
if [[ ! -f "$FILE" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Filename
|
||||||
|
if [[ ! $(isValidFileName "$FILE") = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tInvalid file name.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(hasPhpLogging "$FILE") = 1 ]]; then
|
||||||
|
echo -e "\e[1;33m\tWarning, the commit contains a call to var_dump() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(js)$ ]] && [[ $(hasJsLogging "$FILE") = 1 ]]; then
|
||||||
|
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$1'. Commit was not aborted, however.\e[0m" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhanTestSuccessfull "$FILE") ]]; then
|
||||||
|
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhpStanTestSuccessfull "$FILE") ]]; then
|
||||||
|
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Syntax
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]]; then
|
||||||
|
PHP_SYNTAX = $(hasInvalidPhpSyntax "$FILE")
|
||||||
|
|
||||||
|
if [[ $PHP_SYNTAX = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tPhp linting error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $PHP_SYNTAX = 2 ]]; then
|
||||||
|
echo -e "\e[1;31m\tCode Sniffer error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $PHP_SYNTAX = 3 ]]; then
|
||||||
|
echo -e "\e[1;31m\tMess Detector error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ ! $(isValidBashScript "$FILE") ]]; then
|
||||||
|
echo -e "\e[1;31m\tBash linting error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
||||||
|
GEN_SYNTAX = $(hasInvalidBasicSyntax "$FILE")
|
||||||
|
|
||||||
|
if [[ $GEN_SYNTAX = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound whitespace at end of line in $1.\e[0m" >&2
|
||||||
|
grep -P ' $' $1 >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $GEN_SYNTAX = 2 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound tab instead of whitespace $1.\e[0m" >&2
|
||||||
|
grep -P '\t' $1 >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
||||||
|
TPL_SYNTAX = $(hasInvalidHtmlTemplateContent "$FILE")
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
||||||
|
grep -P '(\<img)((?!.*?alt=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 2 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing input type attribute.\e[0m" >&2
|
||||||
|
grep -P '(<input)((?!.*?type=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 3 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing form element name.\e[0m" >&2
|
||||||
|
grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 4 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing form element action, method or id.\e[0m" >&2
|
||||||
|
grep -P '(\<form)((?!.*?(action|method|id)=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 5 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound inline styles.\e[0m" >&2
|
||||||
|
grep -P '(style=)' "$FILE" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 6 ]]; then
|
||||||
|
echo -e "\e[1;31m\tAttribute description should not be hard coded.\e[0m" >&2
|
||||||
|
grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' "$FILE" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 7 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound hard coded text.\e[0m" >&2
|
||||||
|
grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+' "$FILE" >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
allownonascii="false"
|
isValidFileName() {
|
||||||
|
allownonascii="false"
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
if [ "$allownonascii" != "true" ] &&
|
||||||
|
test $(git diff --cached --name-only --diff-filter=A -z $1 |
|
||||||
|
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$allownonascii" != "true" ] &&
|
return 1
|
||||||
test $(git diff --cached --name-only --diff-filter=A -z $FILE |
|
}
|
||||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
|
||||||
then
|
|
||||||
echo -e "\e[1;31m\tInvalid file name.\e[0m" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
done || exit $?
|
|
||||||
|
|
@ -1,20 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
hasPhpLogging() {
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]]; then
|
RESULT=$(grep "var_dump(" "$1")
|
||||||
RESULT=$(grep "var_dump(" "$FILE")
|
|
||||||
if [ ! -z $RESULT ]; then
|
if [ ! -z $RESULT ]; then
|
||||||
echo -e "\e[1;33m\tWarning, the commit contains a call to var_dump() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
return 0;
|
||||||
if [[ "$FILE" =~ ^.+(js)$ ]]; then
|
}
|
||||||
RESULT=$(grep "console.log(" "$FILE")
|
|
||||||
|
hasJsLogging() {
|
||||||
|
RESULT=$(grep "console.log(" "$1")
|
||||||
if [ ! -z $RESULT ]; then
|
if [ ! -z $RESULT ]; then
|
||||||
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
return 1;
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
done || exit $?
|
return 0;
|
||||||
|
}
|
||||||
136
Hooks/syntax.sh
136
Hooks/syntax.sh
|
|
@ -1,121 +1,85 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
hasInvalidPhpSyntax() {
|
||||||
|
# php lint
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]]; then
|
php -l "$1"
|
||||||
if [[ -f $FILE ]]; then
|
if [ $? -ne 0 ]; then
|
||||||
# php lint
|
return 1
|
||||||
php -l "$FILE"
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "\e[1;31m\tPhp linting error.\e[0m" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# phpcs
|
|
||||||
php -d memory_limit=4G ${rootpath}/vendor/bin/phpcs --standard="${rootpath}/Build/Config/phpcs.xml" --encoding=utf-8 -n -p $FILE
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "\e[1;31m\tCode Sniffer error.\e[0m" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# phpmd
|
|
||||||
php -d memory_limit=4G ${rootpath}/vendor/bin/phpmd $FILE text ${rootpath}/Build/Config/phpmd.xml --exclude *tests* --minimumpriority 1
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "\e[1;31m\tMess Detector error.\e[0m" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Html/template checks
|
|
||||||
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
|
||||||
# Invalid and empty attributes
|
|
||||||
if [[ -n $(grep -E '=\"[\#\$\%\^\&\*\(\)\\/\ ]*\"' $FILE) ]]; then
|
|
||||||
echo -e "\e[1;31m\tFound invalid attribute.\e[0m" >&2
|
|
||||||
grep -E '=\"[\#\$\%\^\&\*\(\)\\/\ ]*\"' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Invalid class/id names
|
# phpcs
|
||||||
if [[ -n $(grep -E '(id|class)=\"[a-zA-Z]*[\#\$\%\^\&\*\(\)\\/\ ]+[a-zA-Z]*\"' $FILE) ]]; then
|
php -d memory_limit=4G ${rootpath}/vendor/bin/phpcs --standard="${rootpath}/Build/Config/phpcs.xml" --encoding=utf-8 -n -p "$1"
|
||||||
echo -e "\e[1;31m\tFound invalid class/id.\e[0m" >&2
|
if [ $? -ne 0 ]; then
|
||||||
grep -E '(id|class)=\"[a-zA-Z]*[\#\$\%\^\&\*\(\)\\/\ ]+[a-zA-Z]*\"' $FILE >&2
|
return 2
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# phpmd
|
||||||
|
php -d memory_limit=4G ${rootpath}/vendor/bin/phpmd "$1" text ${rootpath}/Build/Config/phpmd.xml --exclude *tests* --minimumpriority 1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasInvalidHtmlTemplateContent() {
|
||||||
# Images must have a alt= attribute *error*
|
# Images must have a alt= attribute *error*
|
||||||
if [[ -n $(grep -P '(\<img)((?!.*?alt=).)*(>)' $FILE) ]]; then
|
if [[ -n $(grep -P '(\<img)((?!.*?alt=).)*(>)' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
return 1
|
||||||
grep -P '(\<img)((?!.*?alt=).)*(>)' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Input elements must have a type= attribute *error*
|
# Input elements must have a type= attribute *error*
|
||||||
if [[ -n $(grep -P '(<input)((?!.*?type=).)*(>)' $FILE) ]]; then
|
if [[ -n $(grep -P '(<input)((?!.*?type=).)*(>)' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound missing input type attribute.\e[0m" >&2
|
return 2
|
||||||
grep -P '(<input)((?!.*?type=).)*(>)' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Form fields must have a name *error*
|
# Form fields must have a name *error*
|
||||||
if [[ -n $(grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)' $FILE) ]]; then
|
if [[ -n $(grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound missing form element name.\e[0m" >&2
|
return 3
|
||||||
grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Form must have a id, action and method *error*
|
# Form must have a id, action and method *error*
|
||||||
if [[ -n $(grep -P '(\<form)((?!.*?(action|method|id)=).)*(>)' $FILE) ]]; then
|
if [[ -n $(grep -P '(\<form)((?!.*?(action|method|id)=).)*(>)' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound missing form element action, method or id.\e[0m" >&2
|
return 4
|
||||||
grep -P '(\<form)((?!.*?(action|method|id)=).)*(>)' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Inline css is invalid *warning*
|
# Inline css is invalid *warning*
|
||||||
if [[ -n $(grep -P '(style=)' $FILE) ]]; then
|
if [[ -n $(grep -P '(style=)' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound inline styles.\e[0m" >&2
|
return 5
|
||||||
grep -P '(style=)' $FILE >&2
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Attribute descriptions should not be hard coded *warning*
|
# Attribute descriptions should not be hard coded *warning*
|
||||||
if [[ -n $(grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' $FILE) ]]; then
|
if [[ -n $(grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tAttribute description should not be hard coded.\e[0m" >&2
|
return 6
|
||||||
grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' $FILE >&2
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Hard coded language *warning*
|
# Hard coded language *warning*
|
||||||
if [[ -n $(grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+' $FILE) ]]; then
|
if [[ -n $(grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound hard coded text.\e[0m" >&2
|
return 7
|
||||||
grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+' $FILE >&2
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(sh)$ ]]; then
|
return 0
|
||||||
if [[ -f $FILE ]]; then
|
}
|
||||||
# sh lint
|
|
||||||
bash -n "$FILE" 1> /dev/null
|
isValidBashScript() {
|
||||||
if [ $? -ne 0 ]; then
|
bash -n "$1" 1> /dev/null
|
||||||
echo -e "\e[1;31m\tBash linting error.\e[0m" >&2
|
if [ $? -ne 0 ]; then
|
||||||
exit 1
|
return 0
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# text files in general
|
return 1
|
||||||
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
}
|
||||||
|
|
||||||
|
hasInvalidBasicSyntax() {
|
||||||
# Check whitespace end of line in code
|
# Check whitespace end of line in code
|
||||||
if [[ -n $(grep -P ' $' $FILE) ]]; then
|
if [[ -n $(grep -P ' $' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound whitespace at end of line in $FILE.\e[0m" >&2
|
return 1
|
||||||
grep -P ' $' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for tabs
|
# Check for tabs
|
||||||
if [[ -n $(grep -P '\t' $FILE) ]]; then
|
if [[ -n $(grep -P '\t' $1) ]]; then
|
||||||
echo -e "\e[1;31m\tFound tab instead of whitespace $FILE.\e[0m" >&2
|
return 2
|
||||||
grep -P '\t' $FILE >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
done || exit $?
|
return 0
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
isPhanTestSuccessfull() {
|
||||||
|
php -d memory_limit=4G ${rootpath}/vendor/bin/phan -k ${rootpath}/Build/Config/phan.php -f "$1"
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]]; then
|
if [ $? -ne 0 ]; then
|
||||||
if [[ -f $FILE ]]; then
|
return 0;
|
||||||
# phan
|
|
||||||
php -d memory_limit=4G ${rootpath}/vendor/bin/phan -k ${rootpath}/Build/Config/phan.php -f $FILE
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
# phpstan
|
|
||||||
php -d memory_limit=4G ${rootpath}/vendor/bin/phpstan analyse --autoload-file=${rootpath}/phpOMS/Autoloader.php -l 7 -c ${rootpath}/Build/Config/phpstan.neon $FILE
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
done || exit $?
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
isPhpStanTestSuccessfull() {
|
||||||
|
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"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
return 0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
||||||
124
Hooks/travis.sh
Normal file
124
Hooks/travis.sh
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. ${rootpath}/Build/Hooks/logging.sh
|
||||||
|
. ${rootpath}/Build/Hooks/syntax.sh
|
||||||
|
. ${rootpath}/Build/Hooks/filename.sh
|
||||||
|
. ${rootpath}/Build/Hooks/tests.sh
|
||||||
|
|
||||||
|
($(git diff --name-only $TRAVIS_COMMIT_RANGE)) | while read FILE; do
|
||||||
|
if [[ ! -f "$FILE" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Filename
|
||||||
|
if [[ ! $(isValidFileName "$FILE") = 1]]; then
|
||||||
|
echo -e "\e[1;31m\tInvalid file name.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(hasPhpLogging "$FILE") = 1]]; then
|
||||||
|
echo -e "\e[1;33m\tWarning, the commit contains a call to var_dump() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(js)$ ]] && [[ $(hasJsLogging "$FILE") = 1]]; then
|
||||||
|
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$1'. Commit was not aborted, however.\e[0m" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhanTestSuccessfull "$FILE")]]; then
|
||||||
|
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhpStanTestSuccessfull "$FILE")]]; then
|
||||||
|
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Syntax
|
||||||
|
if [[ "$FILE" =~ ^.+(php)$ ]]; then
|
||||||
|
PHP_SYNTAX = $(hasInvalidPhpSyntax "$FILE")
|
||||||
|
|
||||||
|
if [[ $PHP_SYNTAX = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tPhp linting error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $PHP_SYNTAX = 2 ]]; then
|
||||||
|
echo -e "\e[1;31m\tCode Sniffer error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $PHP_SYNTAX = 3 ]]; then
|
||||||
|
echo -e "\e[1;31m\tMess Detector error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ ! $(isValidBashScript "$FILE")]]; then
|
||||||
|
echo -e "\e[1;31m\tBash linting error.\e[0m" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
||||||
|
GEN_SYNTAX = $(hasInvalidBasicSyntax "$FILE")
|
||||||
|
|
||||||
|
if [[ $GEN_SYNTAX = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound whitespace at end of line in $1.\e[0m" >&2
|
||||||
|
grep -P ' $' $1 >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $GEN_SYNTAX = 2 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound tab instead of whitespace $1.\e[0m" >&2
|
||||||
|
grep -P '\t' $1 >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
||||||
|
TPL_SYNTAX = $(hasInvalidHtmlTemplateContent "$FILE")
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 1 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
||||||
|
grep -P '(\<img)((?!.*?alt=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 2 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing input type attribute.\e[0m" >&2
|
||||||
|
grep -P '(<input)((?!.*?type=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 3 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing form element name.\e[0m" >&2
|
||||||
|
grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 4 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound missing form element action, method or id.\e[0m" >&2
|
||||||
|
grep -P '(\<form)((?!.*?(action|method|id)=).)*(>)' "$FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 5 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound inline styles.\e[0m" >&2
|
||||||
|
grep -P '(style=)' "$FILE" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 6 ]]; then
|
||||||
|
echo -e "\e[1;31m\tAttribute description should not be hard coded.\e[0m" >&2
|
||||||
|
grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' "$FILE" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TPL_SYNTAX = 7 ]]; then
|
||||||
|
echo -e "\e[1;31m\tFound hard coded text.\e[0m" >&2
|
||||||
|
grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+' "$FILE" >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
@ -5,6 +5,7 @@ apt-get update
|
||||||
apt-get install git php7.2 php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-pdo php7.2-sqlite php7.2-mbstring php7.2-curl php7.2-imap php7.2-bcmath php7.2-zip php7.2-dom php7.2-xml php7.2-phar php7.2-gd php7.2-dev php-pear apache2 mysql-server
|
apt-get install git php7.2 php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-pdo php7.2-sqlite php7.2-mbstring php7.2-curl php7.2-imap php7.2-bcmath php7.2-zip php7.2-dom php7.2-xml php7.2-phar php7.2-gd php7.2-dev php-pear apache2 mysql-server
|
||||||
|
|
||||||
a2enmod rewrite
|
a2enmod rewrite
|
||||||
|
a2enmod headers
|
||||||
|
|
||||||
pecl install ast
|
pecl install ast
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user