From a8d4325306df6481d2d3ca4cba353648b0c226c5 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 23 Feb 2025 19:37:54 +0800 Subject: [PATCH 1/3] Warn if commit subject doesn't start with a verb Change-Id: I80a36763282b273d3381f362fd8220657a458ec3 --- scripts/commit-msg.hook | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 9b9ec3283..7e9c1b48d 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -282,6 +282,12 @@ validate_commit_message() { add_warning 1 "Avoid using parentheses '()' in commit subjects" fi + # 7c. Alert if the commit subject starts with "Implementation" + # ------------------------------------------------------------------------------ + if [[ "${COMMIT_SUBJECT_TO_PROCESS}" =~ ^(First|My|Implementation|Creation|Modification) ]]; then + add_warning 1 "Commit subject should use imperative mood" + fi + # 8. Use the body to explain what and why vs. how # ------------------------------------------------------------------------------ From e62fc299dfc9b57bf9b2fdc2ff54173b329deca1 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 23 Feb 2025 19:44:19 +0800 Subject: [PATCH 2/3] Wrap the body at 72 characters This commit fixes line length detection in commit 35ebb65 caused by interference from the prepare-commit-msg hook. Change-Id: I1feaff2b11cafe13fd265a85c82914e33feca827 --- scripts/commit-msg.hook | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 7e9c1b48d..da6be14d3 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -251,19 +251,31 @@ validate_commit_message() { URL_REGEX='^[[:blank:]]*(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]' - # Ensure the commit message lines are loaded into an array. - readarray -t COMMIT_MSG_LINES < "$COMMIT_MSG_FILE" - - for i in "${!COMMIT_MSG_LINES[@]}"; do - LINE="${COMMIT_MSG_LINES[$i]}" - # Trim leading and trailing whitespace. - TRIMMED_LINE="${LINE#"${LINE%%[![:space:]]*}"}" - TRIMMED_LINE="${TRIMMED_LINE%"${TRIMMED_LINE##*[![:space:]]}"}" - LINE_NUMBER=$((i+1)) - if [ "${#TRIMMED_LINE}" -gt 72 ] && ! [[ "$TRIMMED_LINE" =~ $URL_REGEX ]]; then - add_warning "$LINE_NUMBER" "Wrap the body at 72 characters (${#TRIMMED_LINE} chars)" - fi - done +# Ensure the commit message lines are loaded into an array. +readarray -t COMMIT_MSG_LINES < "$COMMIT_MSG_FILE" + +for i in "${!COMMIT_MSG_LINES[@]}"; do + # Skip the first line (the subject) because the limit applies to the body. + if [ "$i" -eq 0 ]; then + continue + fi + + LINE="${COMMIT_MSG_LINES[$i]}" + + # Skip the line if it is a comment. + if [[ "$LINE" =~ ^[[:space:]]*# ]]; then + continue + fi + + # Trim leading and trailing whitespace. + TRIMMED_LINE="${LINE#"${LINE%%[![:space:]]*}"}" + TRIMMED_LINE="${TRIMMED_LINE%"${TRIMMED_LINE##*[![:space:]]}"}" + LINE_NUMBER=$((i+1)) + + if [ "${#TRIMMED_LINE}" -gt 72 ] && ! [[ "$TRIMMED_LINE" =~ $URL_REGEX ]]; then + add_warning "$LINE_NUMBER" "Wrap the body at 72 characters (${#TRIMMED_LINE} chars)" + fi +done # 7. Ensure the commit subject has more than one word. # ------------------------------------------------------------------------------ From 6c6aa7d38e325f55643eac02aad4a688ba193e34 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 23 Feb 2025 19:56:17 +0800 Subject: [PATCH 3/3] Suppress Cppcheck report Change-Id: I4e5fa6178f099962d93501721a3eb7d0e3a04509 --- scripts/pre-commit.hook | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pre-commit.hook b/scripts/pre-commit.hook index cdf30c597..14f08de25 100755 --- a/scripts/pre-commit.hook +++ b/scripts/pre-commit.hook @@ -8,6 +8,7 @@ done # We suppress the checkLevelNormal warning for Cppcheck versions 2.11 and above. # Please refer to issues/153 for more details. CPPCHECK_suppresses="--inline-suppr harness.c \ +--suppress=checkersReport \ --suppress=unmatchedSuppression \ --suppress=normalCheckLevelMaxBranches \ --suppress=missingIncludeSystem \