From a59fa7eca040127805398a2eec66441b3d718658 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 18 Feb 2024 14:27:15 +0100 Subject: [PATCH] Test --- .pre-commit-config.yaml | 6 +-- dev/setup/git/hooks/pre-commit.legacy | 72 ++++++++++++++------------- htdocs/core/customreports.php | 4 +- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 295849b977d..417f5cd56a8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: | diff --git a/dev/setup/git/hooks/pre-commit.legacy b/dev/setup/git/hooks/pre-commit.legacy index 70a4384edfe..57c722abd49 100755 --- a/dev/setup/git/hooks/pre-commit.legacy +++ b/dev/setup/git/hooks/pre-commit.legacy @@ -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 diff --git a/htdocs/core/customreports.php b/htdocs/core/customreports.php index 40d44342148..11d5dcf7eda 100644 --- a/htdocs/core/customreports.php +++ b/htdocs/core/customreports.php @@ -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'); }