update building / inspection script

This commit is contained in:
Dennis Eichhorn 2022-04-10 17:18:50 +02:00
parent 1577c5386d
commit 9ba4adf727
7 changed files with 67 additions and 20 deletions

29
Helper/inspectproject.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# html checks
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -E '=\"[\#\$\%\^\&\*\(\)\\/\ ]*\"'
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -P '(\<img)((?!.*?alt=).)*(>)'
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -P '(<input)((?!.*?type=).)*(>)'
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)'
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -P '(style=)'
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)'
find ./Web ./Install ./Modules -name "*tpl.php" | xargs grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+)'
# php/js strict checks
grep -r -L "declare(strict_types=1);" --include=*.php --exclude={*.tpl.php,*Hooks.php,*Routes.php,*SearchCommands.php} ./phpOMS ./Web ./Modules ./Model
grep -r -L "\"use strict\";" --include=*.js ./jsOMS ./Modules ./Model
# php/js has logs
find ./Web ./phpOMS ./Model ./Modules -name "*.js" | xargs grep 'console.log('
find ./Web ./jsOMS ./Model ./Modules -name "*.php" | xargs grep 'var_dump('
# js uses on actions
grep -rlni "onafterprint=\|onbeforeprint=\|onbeforeunload=\|onerror=\|onhaschange=\|onload=\|onmessage=\|onoffline=\|ononline=\|onpagehide=\|onpageshow=\|onpopstate=\|onredo=\|onresize=\|onstorage=\|onund=o\|onunload=\|onblur=\|onchage=\|oncontextmenu=\|onfocus=\|onformchange=\|onforminput=\|oninput=\|oninvalid=\|onreset=\|onselect=\|onsubmit=\|onkeydown=\|onkeypress=\|onkeyup=\|onclick=\|ondblclic=k\|ondrag=\|ondragend=\|ondragenter=\|ondragleave=\|ondragover=\|ondragstart=\|ondrop=\|onmousedown=\|onmousemove=\|onmouseout=\|onmouseover=\|onmouseup=\|onmousewheel=\|onscroll=\|onabor=t\|oncanplay=\|oncanplaythrough=\|ondurationchange=\|onemptied=\|onended=\|onerror=\|onloadeddata=\|onloadedmetadata=\|onloadstart=\|onpause=\|onplay=\|onplaying=\|onprogress=\|onratechange=\|onreadystatechange=\|onseeked=\|onseeking=\|onstalled=\|onsuspend=\|ontimeupdate=\|onvolumechange=" --include=*.js ./jsOMS ./Model ./Modules ./Web
# white spaces at end of line
find ./Web ./phpOMS ./jsOMS ./cOMS ./Model ./Build ./Modules \( -name "*.php" -o -name "*.js" -o -name "*.sh" -o -name "*.cpp" -o -name "*.h" -o -name "*.json" \) | xargs grep -P ' $'
# php cs + phpstan + eslint
./vendor/bin/phpcs ./ --standard="Build/Config/phpcs.xml"
./vendor/bin/phpstan analyse --autoload-file=phpOMS/Autoloader.php -l 9 -c Build/Config/phpstan.neon ./
npx eslint jsOMS/ -c Build/Config/.eslintrc.json

View File

@ -2,10 +2,7 @@
mkdir -p Build/test
./vendor/bin/phpcs ./ --standard="Build/Config/phpcs.xml"
./vendor/bin/phpstan analyse --autoload-file=phpOMS/Autoloader.php -l 9 -c Build/Config/phpstan.neon ./
npx eslint jsOMS/ -c Build/Config/.eslintrc.json
# php cs + phpstan + eslint file generation
./vendor/bin/phpcs ./ --standard="Build/Config/phpcs.xml" -s --report-junit=Build/test/junit_phpcs.xml
./vendor/bin/phpstan analyse --autoload-file=phpOMS/Autoloader.php -l 9 -c Build/Config/phpstan.neon --error-format=prettyJson ./ > Build/test/phpstan.json
npx eslint jsOMS/ -c Build/Config/.eslintrc.json -o Build/test/junit_eslint.xml -f junit
@ -14,6 +11,7 @@ npx eslint jsOMS/ -c Build/Config/.eslintrc.json -o Build/test/junit_eslint.xml
sed -i '/^$/d' Build/test/phpstan.json
sed -i '/^Warning: /d' Build/test/phpstan.json
# Create report
php ../TestReportGenerator/src/index.php \
-b /home/spl1nes/Orange-Management \
-l /home/spl1nes/Orange-Management/Build/Config/reportLang.php \

View File

@ -32,11 +32,6 @@ for FILE in $(git diff --cached --name-only); do
fi
# Tests
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(isPhanTestSuccessful "$FILE") = 0 ]]; then
echo -e "\e[1;31m\tPhan error in $FILE.\e[0m" >&2
exit 1
fi
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(isPhpStanTestSuccessful "$FILE") = 0 ]]; then
echo -e "\e[1;31m\tPhp stan error in $FILE.\e[0m" >&2
exit 1
@ -63,6 +58,16 @@ for FILE in $(git diff --cached --name-only); do
fi
fi
if [[ "$FILE" =~ ^.+(js)$ ]]; then
PHP_SYNTAX=$(hasInvalidJsSyntax "$FILE")
if [[ $PHP_SYNTAX = 1 ]]; then
echo -e "\e[1;31m\tEslint error.\e[0m" >&2
npx eslint "$FILE" -c Build/Config/.eslintrc.json
exit 1
fi
fi
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ $(isValidBashScript "$FILE") = 0 ]]; then
echo -e "\e[1;31m\tBash linting error in '$FILE'.\e[0m" >&2
exit 1

View File

@ -15,11 +15,16 @@ hasInvalidPhpSyntax() {
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)
echo 0
return 0
}
hasInvalidJsSyntax() {
# eslint
$(npx eslint "$1" -c Build/Config/.eslintrc.json > /dev/null)
if [[ $? != 0 ]]; then
echo 3
return 3
echo 1
return 1
fi
echo 0

View File

@ -3,10 +3,14 @@
. config.sh
echo "#################################################"
echo "Start html attributes inspection"
echo "Start html inspection"
echo "#################################################"
# Find invalid attributes
find ${ROOT_PATH} -name "*tpl.php" | xargs grep -E '=\"[\#\$\%\^\&\*\(\)\\/\ ]*\"' > ${INSPECTION_PATH}/Modules/html/attributes_invalid.log
find ${ROOT_PATH} -name "*tpl.php" | xargs grep -E '(id|class)=\"[a-zA-Z]*[\#\$\%\^\&\*\(\)\\/\ ]+[a-zA-Z]*\"' >> ${INSPECTION_PATH}/Modules/html/attributes_invalid.log
find ${ROOT_PATH} -name "*tpl.php" | xargs grep -P '(\<img)((?!.*?alt=).)*(>)' >> ${INSPECTION_PATH}/Modules/html/attributes_invalid.log
# Find invalid html
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -E '=\"[\#\$\%\^\&\*\(\)\\/\ ]*\"' > ${INSPECTION_PATH}/Modules/html/invalid_html.log
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -P '(\<img)((?!.*?alt=).)*(>)' >> ${INSPECTION_PATH}/Modules/html/invalid_html.log
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -P '(<input)((?!.*?type=).)*(>)' >> ${INSPECTION_PATH}/Modules/html/invalid_html.log
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -P '(<input|<select|<textarea)((?!.*?name=).)*(>)' >> ${INSPECTION_PATH}/Modules/html/invalid_html.log
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -P '(style=)' >> ${INSPECTION_PATH}/Modules/html/invalid_html.log
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -P '(value|title|alt|aria\-label)(=\")((?!\<\?).)*(>)' >> ${INSPECTION_PATH}/Modules/html/invalid_html.log
find {ROOT_PATH}/Web {ROOT_PATH}/phpOMS {ROOT_PATH}/Build {ROOT_PATH}/Modules -name "*tpl.php" | xargs grep -P '(\<td\>|\<th\>|\<caption\>|\<label.*?(\"|l)\>)[0-9a-zA-Z\.\?]+)' >> ${INSPECTION_PATH}/Modules/html/invalid_html.log

View File

@ -50,6 +50,12 @@ echo "Custom php inspection"
echo "#################################################"
. ${BUILD_PATH}/Inspection/Php/security.sh
# Custom js inspections
echo "#################################################"
echo "Custom js inspection"
echo "#################################################"
. ${BUILD_PATH}/Inspection/Js/security.sh
# Build external test report
echo "#################################################"
echo "Test report"