From b692275c3111faf4a4529c8398bcea182a0c5fb3 Mon Sep 17 00:00:00 2001 From: mochou Date: Sat, 15 Nov 2025 17:17:03 +0800 Subject: [PATCH] fix(qmlfmt): Add compatibility for qmlformat command - Modifies Bin/dev/qmlfmt.sh to check for both 'qmlfmt' and 'qmlformat' executables. - Uses 'qmlfmt' with its original arguments if found. - If 'qmlfmt' is not found, uses 'qmlformat' with arguments for 2-space indentation and essential semicolons. - Exits with an error if neither command is available. - This makes the QML formatting pre-commit hook more robust. --- Bin/dev/qmlfmt.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Bin/dev/qmlfmt.sh b/Bin/dev/qmlfmt.sh index 8d09aa3d..6a99053e 100755 --- a/Bin/dev/qmlfmt.sh +++ b/Bin/dev/qmlfmt.sh @@ -5,9 +5,18 @@ set -euo pipefail # Uses: https://github.com/jesperhh/qmlfmt # Install: AUR package "qmlfmt-git" (requires qt6-5compat) -command -v qmlfmt &>/dev/null || { echo "qmlfmt not found" >&2; exit 1; } +# Find the available QML formatter command and define format_file accordingly +if command -v qmlfmt &>/dev/null; then + echo "Using 'qmlfmt' for formatting." + format_file() { qmlfmt -e -b 360 -t 2 -i 2 -w "$1" || { echo "Failed: $1" >&2; return 1; }; } +elif command -v qmlformat &>/dev/null; then + echo "Using 'qmlformat' for formatting." + format_file() { qmlformat -i --indent-width 2 --semicolon-rule essential "$1" || { echo "Failed: $1" >&2; return 1; }; } +else + echo "Neither 'qmlfmt' nor 'qmlformat' found in PATH." >&2 + exit 1 +fi -format_file() { qmlfmt -e -b 360 -t 2 -i 2 -w "$1" || { echo "Failed: $1" >&2; return 1; }; } export -f format_file # Find all .qml files