Skip to content

Commit fe7662b

Browse files
committed
Avoid using abusive words
Validate the entire commit message for abusive language. Only a small set of abusive words was detected. Change-Id: Ib59b2c04f7edfc34fd68873dc58df1419be49b95
1 parent 490b66e commit fe7662b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

scripts/commit-msg.hook

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,29 @@ validate_commit_message() {
282282

283283
word_count=$(echo "$COMMIT_SUBJECT_TO_PROCESS" | wc -w)
284284
test "$word_count" -gt 1
285-
test $? -eq 0 || add_warning 1 "Commit subject should contain more than one word (e.g. 'Update dependencies' instead of 'Update')"
285+
test $? -eq 0 || add_warning 1 "Commit subject should contain more than one word. Summarize your changes"
286286

287287
# 11. Avoid commit subject that simply states a file update (e.g. "Update console.c")
288+
# ------------------------------------------------------------------------------
289+
288290
if [[ $COMMIT_SUBJECT_TO_PROCESS =~ ^Update[[:space:]]+([^[:space:]]+)$ ]]; then
289291
candidate="${BASH_REMATCH[1]}"
290292
# Only warn if the candidate filename ends with .c or .h
291293
if [[ $candidate =~ \.(c|h)$ ]]; then
292294
add_warning 1 "Avoid using just a filename like '$candidate'. Provide a functional, meaningful description"
293295
fi
294296
fi
297+
298+
# 12. Avoid abusive language in commit message content
299+
# ------------------------------------------------------------------------------
300+
301+
FULL_COMMIT_MSG=$(sed '/^#/d;/^[[:space:]]*$/d' "$COMMIT_MSG_FILE")
302+
# Extended list of abusive words (case-insensitive).
303+
# Adjust the list as needed.
304+
ABUSIVE_WORDS_REGEX='\b(fuck|fucking|dick|shit|bitch|asshole|cunt|motherfucker|damn|crap|dumbass|piss)\b'
305+
if echo "$FULL_COMMIT_MSG" | grep -Eiq "$ABUSIVE_WORDS_REGEX"; then
306+
add_warning 1 "Commit message contains inappropriate language. Avoid using abusive words"
307+
fi
295308
}
296309

297310
unset GREP_OPTIONS

0 commit comments

Comments
 (0)