This commit is contained in:
Laurent Destailleur 2024-02-18 14:27:15 +01:00
parent ead53cf4f5
commit a59fa7eca0
3 changed files with 42 additions and 40 deletions

View file

@ -5,11 +5,11 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# This hook test the name of the branch and return error if the name is develop or a version
# This hook test the name of the branch and return error if the name is 'develop' or an official version 'x.y'
# so you can't commit if your branch name is not a custom branch name. Using a custom branch name is good
# practice that make easier to manage PR. You can disable this if you still want to commit on branch with common names.
- id: no-commit-to-branch
args: [--branch, develop, --pattern, \d+.0]
#- id: no-commit-to-branch
# args: [--branch, develop, --pattern, \d+.0]
# This check format of xml files
- id: check-xml
exclude: |

View file

@ -6,6 +6,8 @@
# When running git commit, it first execute this file checking only modified files, so it is faster than running on all files
# To run the fix manually: cd ~/git/dolibarr; phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true "fileordir"
# NOTE: Use the pre-commit hook file with the tool pre-commit install is a better choice.
PROJECT=$(php -r "echo dirname(dirname(dirname(realpath('$0'))));")
STAGED_FILES_CMD=$(git diff --cached --name-only --diff-filter=ACMR HEAD | grep -v '/includes/'| grep \\\\.php)
DIRPHPCS=""
@ -16,10 +18,10 @@ echo "Running precommit hook in .git/hooks/pre-commit" 1>&2
# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS=$'\n'
SFILES="$1"
IFS=$oIFS
oIFS=$IFS
IFS=$(printf '\n')
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}
@ -27,50 +29,50 @@ echo "Checking PHP Lint with php -l ..."
for FILE in $SFILES
do
php -l -d display_errors=0 "$PROJECT/$FILE"
php -l -d display_errors=0 "$PROJECT/$FILE"
result1=$?
result1=$?
if [ "x$result1" != "x0" ]
then
echo "Fix the error before commit." 1>&2
exit 1
fi
# shellcheck disable=2089
FILES="$FILES '$PROJECT/$FILE'"
if [ "x$result1" != "x0" ]
then
echo "Fix the error before commit." 1>&2
exit 1
fi
# shellcheck disable=2089
FILES="$FILES '$PROJECT/$FILE'"
done
if [ "$FILES" != "" ]
then
echo "Running PHPCS Code Sniffer..."
echo "Running PHPCS Code Sniffer..."
# Check Dolibarr standard
# shellcheck disable=2086,2090
"${DIRPHPCS}phpcs" -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
# Check Dolibarr standard
# shellcheck disable=2086,2090
"${DIRPHPCS}phpcs" -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
# Check a common standard
#${DIRPHPCS}phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=PSR2 --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
# Check a common standard
#${DIRPHPCS}phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=PSR2 --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
result2=$?
result2=$?
if [ "x$result2" != "x0" ]
then
# Fix standard errors
if [ "x$AUTOFIX" != "x0" ]
then
# shellcheck disable=2086,2090
"${DIRPHPCS}phpcbf" -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
if [ "x$result2" != "x0" ]
then
# Fix standard errors
if [ "x$AUTOFIX" != "x0" ]
then
# shellcheck disable=2086,2090
"${DIRPHPCS}phpcbf" -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
#${DIRPHPCS}phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
#${DIRPHPCS}phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
echo "Found some errors in syntax rules. An automatic fix has been applied. Check it before commit." 1>&2
exit 1
else
echo "Found some errors in syntax rules. Fix the error(s) before commit." 1>&2;
exit 1
fi
fi
echo "Found some errors in syntax rules. An automatic fix has been applied. Check it before commit." 1>&2
exit 1
else
echo "Found some errors in syntax rules. Fix the error(s) before commit." 1>&2;
exit 1
fi
fi
fi
exit 0

View file

@ -24,7 +24,7 @@
* \ingroup core
* \brief Page to make custom reports. Page can be used alone or as a tab among other tabs of an object
*/
ffd df f gd dfgdf
if (!defined('USE_CUSTOM_REPORT_AS_INCLUDE')) {
require '../main.inc.php';
@ -40,7 +40,7 @@ if (!defined('USE_CUSTOM_REPORT_AS_INCLUDE')) {
$objecttype = 'thirdparty';
}
$search_me asures = GETPOST('search_measures', 'array');
$search_measures = GETPOST('search_measures', 'array');
if (empty($search_measures)) {
$search_measures = array(0 => 't.count');
}