diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 9b9ec3283..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. # ------------------------------------------------------------------------------ @@ -282,6 +294,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 # ------------------------------------------------------------------------------ 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 \