From a3d4a0bc86e06e542b540ebd1f7186afb54cd107 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 21 Feb 2025 23:26:25 +0800 Subject: [PATCH 1/2] Enforce American English in commit messages This commit introduces a spell checker configured for American English. The commit-msg hook aborts the commit if aspell detects any words that do not conform to en_US spelling. Change-Id: Ibb36bcf01fc02c52187f66ad8f948e222068d238 --- scripts/aspell-pws | 2 ++ scripts/commit-msg.hook | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/aspell-pws b/scripts/aspell-pws index dedd4fa4e..00d2a452b 100644 --- a/scripts/aspell-pws +++ b/scripts/aspell-pws @@ -298,3 +298,5 @@ tcp awk sed changeid +en +msg diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 62a99eb3d..518ce1a4e 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -322,13 +322,22 @@ validate_commit_message() { # 12. Avoid abusive language in commit message content # ------------------------------------------------------------------------------ - FULL_COMMIT_MSG=$(sed '/^#/d;/^[[:space:]]*$/d' "$COMMIT_MSG_FILE") + FULL_COMMIT_MSG=$(sed '/^#/d;/^[[:space:]]*$/d;/^[[:space:]]*Change-Id:/d' "$COMMIT_MSG_FILE") # Extended list of abusive words (case-insensitive). # Adjust the list as needed. ABUSIVE_WORDS_REGEX='\b(fuck|fucking|dick|shit|bitch|asshole|cunt|motherfucker|damn|crap|dumbass|piss)\b' if echo "$FULL_COMMIT_MSG" | grep -Eiq "$ABUSIVE_WORDS_REGEX"; then add_warning 1 "Commit message contains inappropriate language. Avoid using abusive words" fi + + # 13. Always use American English. + # ------------------------------------------------------------------------------ + + # Use aspell to list misspelled words according to American English. + MISSPELLED_WORDS=$(echo "$FULL_COMMIT_MSG" | $ASPELL --lang=en --list --home-dir=scripts --personal=aspell-pws) + if [ -n "$MISSPELLED_WORDS" ]; then + add_warning 1 "Avoid using non-American English words" + fi } unset GREP_OPTIONS From bb2d2bebc6c6a43685c2c219bcb25adaa51c76fc Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 21 Feb 2025 23:54:40 +0800 Subject: [PATCH 2/2] Filter out hyperlinks There is no need to validate the hyperlinks with spell checkers. Change-Id: I517836c006132c8373f13265672f64cee271dd82 --- scripts/commit-msg.hook | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 518ce1a4e..d542d0bea 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -322,7 +322,8 @@ validate_commit_message() { # 12. Avoid abusive language in commit message content # ------------------------------------------------------------------------------ - FULL_COMMIT_MSG=$(sed '/^#/d;/^[[:space:]]*$/d;/^[[:space:]]*Change-Id:/d' "$COMMIT_MSG_FILE") + FULL_COMMIT_MSG=$(sed '/^#/d;/^[[:space:]]*$/d;/^[[:space:]]*Change-Id:/d' "$COMMIT_MSG_FILE" | \ + sed -E "s@${URL_REGEX#^}@@g") # Extended list of abusive words (case-insensitive). # Adjust the list as needed. ABUSIVE_WORDS_REGEX='\b(fuck|fucking|dick|shit|bitch|asshole|cunt|motherfucker|damn|crap|dumbass|piss)\b'