From 7d89635c5b2fb3e7399433f96128a20aae0f68b5 Mon Sep 17 00:00:00 2001 From: MDW Date: Tue, 17 Feb 2026 22:05:03 +0100 Subject: [PATCH] Qual: Update pre-commit for shell script formatting (#37221) * Qual: Upgrade pre-commit/beautysh, .editorconfig for sh # Qual: Upgrade pre-commit/beautysh, .editorconfig for sh - Upgrade beautysh pre-commit hook (trixie/python 3.13 compatibility); - Indicate tab indent for shell scripts in .editorconfig. * Qual: Update pre-commit hooks configuration - Exclude `dev/initdemo/initdemo.sh` from beautysh hook - Enable shellcheck hook manually - Fix indentation in `initdemo.sh` * Qual: Update pre-commit hook configuration - Update .pre-commit-config.yaml to exclude dolibarr.postrm from beautysh formatting --------- Co-authored-by: Laurent Destailleur --- .editorconfig | 2 + .pre-commit-config.yaml | 31 ++++--- dev/initdemo/initdemo.sh | 90 +++++++++---------- .../sanity_check_trans_missing_unused.sh | 10 +-- 4 files changed, 69 insertions(+), 64 deletions(-) diff --git a/.editorconfig b/.editorconfig index f1d2d2e0864..d627b87f718 100644 --- a/.editorconfig +++ b/.editorconfig @@ -18,6 +18,8 @@ insert_final_newline = true indent_style = tab [*.css] indent_style = tab +[*.sh] +indent_style = tab [*.xml] indent_style = tab [*.md] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4b248d734b..8c761b99696 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -72,14 +72,16 @@ repos: stages: [manual] # To run: pre-commit run -a --hook-stage=manual actionlint # Beautify shell scripts - #- repo: https://github.com/lovesegfault/beautysh.git - # rev: v6.2.1 - # hooks: - # - id: beautysh - # exclude: | - # (?x)^(dev/setup/git/hooks/pre-commit - # )$ - # args: [--tab] + - repo: https://github.com/lovesegfault/beautysh.git + rev: v6.4.2 + hooks: + - id: beautysh + exclude: | + (?x)^(dev/setup/git/hooks/pre-commit + |dev/initdemo/initdemo.sh # indent/outdent mismatch + |dev/build/debian/dolibarr.postrm # indent/outdent mismatch + )$ + args: [--tab] # Run local script # @@ -246,11 +248,12 @@ repos: - ned # Check some shell scripts - #- repo: https://github.com/shellcheck-py/shellcheck-py - # rev: v0.11.0.1 - # hooks: - # - id: shellcheck - # args: [-W, "100"] + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.11.0.1 + hooks: + - id: shellcheck + stages: [manual] # To run: `pre-commit run -a --hook-stage=manual shellcheck` + args: [-W, "100"] # Check sql file syntax - repo: https://github.com/sqlfluff/sqlfluff @@ -293,4 +296,4 @@ repos: # # virtualmin excluded - reason https://github.com/Dolibarr/dolibarr/pull/36370#issuecomment-3565101823 # exclude: (?x)^ # (dev/build/perl/virtualmin/dolibarr.pl - # )$ + # across all file typese )$ diff --git a/dev/initdemo/initdemo.sh b/dev/initdemo/initdemo.sh index 6a6399a286f..73c592fc797 100755 --- a/dev/initdemo/initdemo.sh +++ b/dev/initdemo/initdemo.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (C) 2024 MDW +# Copyright (C) 2024-2026 MDW #------------------------------------------------------ # Script to purge and initialize a database with demo values. @@ -91,7 +91,7 @@ then fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$ # shellcheck disable=2064,2172 trap "rm -f '$fichtemp'" 0 1 2 5 15 - $DIALOG --title "Init Dolibarr with demo values" --clear --inputbox "Mysql database name :" 16 55 $base 2> "$fichtemp" + $DIALOG --title "Init Dolibarr with demo values" --clear --inputbox "Mysql database name :" 16 55 "$base" 2> "$fichtemp" valret=$? case $valret in 0) @@ -107,7 +107,7 @@ then fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$ # shellcheck disable=2064,2172 trap "rm -f '$fichtemp'" 0 1 2 5 15 - $DIALOG --title "Init Dolibarr with demo values" --clear --inputbox "Mysql port (ex: 3306):" 16 55 $port 2> "$fichtemp" + $DIALOG --title "Init Dolibarr with demo values" --clear --inputbox "Mysql port (ex: 3306):" 16 55 "$port" 2> "$fichtemp" valret=$? case $valret in @@ -215,55 +215,55 @@ exit; export documentdir # shellcheck disable=2016 documentdir=$(< "$mydir/../../htdocs/conf/conf.php" grep '^\$dolibarr_main_data_root' | sed -e 's/$dolibarr_main_data_root=//' | sed -e 's/;//' | sed -e "s/'//g" | sed -e 's/"//g') -if [ "$documentdir" != "" ] -then - $DIALOG --title "Reset document directory" --clear --yesno "DELETE and recreate document directory '$documentdir/':" 16 55 - valret=$? + if [ "$documentdir" != "" ] + then + $DIALOG --title "Reset document directory" --clear --yesno "DELETE and recreate document directory '$documentdir/':" 16 55 + valret=$? - case $valret in - 0) - # YES - echo "RECREATE $documentdir" - echo " rm -fr '$documentdir/'*" - rm -fr "${documentdir:?}/"* ;; - 1) - exit ;; - 255) - exit ;; - esac + case $valret in + 0) + # YES + echo "RECREATE $documentdir" + echo " rm -fr '$documentdir/'*" + rm -fr "${documentdir:?}/"* ;; + 1) + exit ;; + 255) + exit ;; + esac - echo "cp -pr '$mydir/documents_demo/'* '$documentdir/'" - cp -pr "$mydir/documents_demo/"* "$documentdir/" + echo "cp -pr '$mydir/documents_demo/'* '$documentdir/'" + cp -pr "$mydir/documents_demo/"* "$documentdir/" - mkdir "$documentdir/doctemplates/" 2>/dev/null - echo cp -pr "$mydir/../../htdocs/install/doctemplates/"* "$documentdir/doctemplates/" - cp -pr "$mydir/../../htdocs/install/doctemplates/"* "$documentdir/doctemplates/" + mkdir "$documentdir/doctemplates/" 2>/dev/null + echo cp -pr "$mydir/../../htdocs/install/doctemplates/"* "$documentdir/doctemplates/" + cp -pr "$mydir/../../htdocs/install/doctemplates/"* "$documentdir/doctemplates/" - echo cp -pr "$mydir/../../htdocs/install/medias/"* "$documentdir/medias/image/" - cp -pr "$mydir/../../htdocs/install/medias/"* "$documentdir/medias/image/" + echo cp -pr "$mydir/../../htdocs/install/medias/"* "$documentdir/medias/image/" + cp -pr "$mydir/../../htdocs/install/medias/"* "$documentdir/medias/image/" - mkdir -p "$documentdir/ecm/Administrative documents" 2>/dev/null - mkdir -p "$documentdir/ecm/Images" 2>/dev/null - rm -f "$documentdir/doctemplates/"*/index.html - echo cp -pr "$mydir/../../doc/images/"* "$documentdir/ecm/Images" - cp -pr "$mydir/../../doc/images/"* "$documentdir/ecm/Images" + mkdir -p "$documentdir/ecm/Administrative documents" 2>/dev/null + mkdir -p "$documentdir/ecm/Images" 2>/dev/null + rm -f "$documentdir/doctemplates/"*/index.html + echo cp -pr "$mydir/../../doc/images/"* "$documentdir/ecm/Images" + cp -pr "$mydir/../../doc/images/"* "$documentdir/ecm/Images" - chmod -R u+w "$documentdir/" - chown -R www-data "$documentdir/" -else - echo "Detection of 'documents' directory in '$mydir' failed so demo files were not copied." -fi + chmod -R u+w "$documentdir/" + chown -R www-data "$documentdir/" + else + echo "Detection of 'documents' directory in '$mydir' failed so demo files were not copied." + fi -if [ -s "$mydir/initdemopostsql.sql" ]; then - mysql "-P$port" "$base" < "$mydir/initdemopostsql.sql" -fi + if [ -s "$mydir/initdemopostsql.sql" ]; then + mysql "-P$port" "$base" < "$mydir/initdemopostsql.sql" + fi -if [ "$res" = "0" ] -then - echo "Success, file successfully loaded." -else - echo "Error, load failed." -fi -echo + if [ "$res" = "0" ] + then + echo "Success, file successfully loaded." + else + echo "Error, load failed." + fi + echo diff --git a/dev/translation/sanity_check_trans_missing_unused.sh b/dev/translation/sanity_check_trans_missing_unused.sh index 5cc1fe07c60..381701bb969 100755 --- a/dev/translation/sanity_check_trans_missing_unused.sh +++ b/dev/translation/sanity_check_trans_missing_unused.sh @@ -23,7 +23,7 @@ # - Some side effects from translations on variables. # - Some other minors side effects to be examined (#, %). # -# Copyright (C) 2024 MDW +# Copyright (C) 2024-2026 MDW LANG_DIR=htdocs/langs/en_US/ MYDIR=$(dirname "$(realpath "$0")") @@ -141,10 +141,10 @@ sed -n 's@< \(.*\)@^\1\\s*=@p' \ # REPL_STR="" for t in trans transnoentities transnoentitiesnoconv newItem buttonsSaveCancel; do - REPL_STR="${REPL_STR}\n->${t}(\"\\1\"," - REPL_STR="${REPL_STR}\n->${t}('\\1'," - REPL_STR="${REPL_STR}\n->${t}(\"\\1\")" - REPL_STR="${REPL_STR}\n->${t}('\\1')" + REPL_STR="${REPL_STR}\n->${t}(\"\\1\"," + REPL_STR="${REPL_STR}\n->${t}('\\1'," + REPL_STR="${REPL_STR}\n->${t}(\"\\1\")" + REPL_STR="${REPL_STR}\n->${t}('\\1')" done rm -f "${MISSING_FILE}.grep" >/dev/null 2>&1