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 <eldy@destailleur.fr>
This commit is contained in:
MDW 2026-02-17 22:05:03 +01:00 committed by GitHub
parent bd2ff84a95
commit 7d89635c5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 64 deletions

View file

@ -18,6 +18,8 @@ insert_final_newline = true
indent_style = tab
[*.css]
indent_style = tab
[*.sh]
indent_style = tab
[*.xml]
indent_style = tab
[*.md]

View file

@ -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 )$

View file

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
# Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
#------------------------------------------------------
# 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

View file

@ -23,7 +23,7 @@
# - Some side effects from translations on variables.
# - Some other minors side effects to be examined (#, %).
#
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
# Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
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