@@ -249,13 +249,21 @@ validate_commit_message() {
249
249
# 6. Wrap the body at 72 characters
250
250
# ------------------------------------------------------------------------------
251
251
252
- URL_REGEX=' ^[[:blank:]]*(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
253
-
254
- for i in " ${! COMMIT_MSG_LINES[@]} " ; do
255
- LINE_NUMBER=$(( i+ 1 ))
256
- test " ${# COMMIT_MSG_LINES[$i]} " -le 72 || [[ ${COMMIT_MSG_LINES[$i]} =~ $URL_REGEX ]]
257
- test $? -eq 0 || add_warning $LINE_NUMBER " Wrap the body at 72 characters (${# COMMIT_MSG_LINES[$i]} chars)"
258
- done
252
+ URL_REGEX=' ^[[:blank:]]*(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]'
253
+
254
+ # Ensure the commit message lines are loaded into an array.
255
+ readarray -t COMMIT_MSG_LINES < " $COMMIT_MSG_FILE "
256
+
257
+ for i in " ${! COMMIT_MSG_LINES[@]} " ; do
258
+ LINE=" ${COMMIT_MSG_LINES[$i]} "
259
+ # Trim leading and trailing whitespace.
260
+ TRIMMED_LINE=" ${LINE# " ${LINE%% [![:space:]]* } " } "
261
+ TRIMMED_LINE=" ${TRIMMED_LINE% " ${TRIMMED_LINE##* [![:space:]]} " } "
262
+ LINE_NUMBER=$(( i+ 1 ))
263
+ if [ " ${# TRIMMED_LINE} " -gt 72 ] && ! [[ " $TRIMMED_LINE " =~ $URL_REGEX ]]; then
264
+ add_warning " $LINE_NUMBER " " Wrap the body at 72 characters (${# TRIMMED_LINE} chars)"
265
+ fi
266
+ done
259
267
260
268
# 7. Use the body to explain what and why vs. how
261
269
# ------------------------------------------------------------------------------
@@ -282,16 +290,29 @@ validate_commit_message() {
282
290
283
291
word_count=$( echo " $COMMIT_SUBJECT_TO_PROCESS " | wc -w)
284
292
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') "
293
+ test $? -eq 0 || add_warning 1 " Commit subject should contain more than one word. Summarize your changes "
286
294
287
295
# 11. Avoid commit subject that simply states a file update (e.g. "Update console.c")
296
+ # ------------------------------------------------------------------------------
297
+
288
298
if [[ $COMMIT_SUBJECT_TO_PROCESS =~ ^Update[[:space:]]+ ([^[:space:]]+)$ ]]; then
289
299
candidate=" ${BASH_REMATCH[1]} "
290
300
# Only warn if the candidate filename ends with .c or .h
291
301
if [[ $candidate =~ \. (c| h)$ ]]; then
292
302
add_warning 1 " Avoid using just a filename like '$candidate '. Provide a functional, meaningful description"
293
303
fi
294
304
fi
305
+
306
+ # 12. Avoid abusive language in commit message content
307
+ # ------------------------------------------------------------------------------
308
+
309
+ FULL_COMMIT_MSG=$( sed ' /^#/d;/^[[:space:]]*$/d' " $COMMIT_MSG_FILE " )
310
+ # Extended list of abusive words (case-insensitive).
311
+ # Adjust the list as needed.
312
+ ABUSIVE_WORDS_REGEX=' \b(fuck|fucking|dick|shit|bitch|asshole|cunt|motherfucker|damn|crap|dumbass|piss)\b'
313
+ if echo " $FULL_COMMIT_MSG " | grep -Eiq " $ABUSIVE_WORDS_REGEX " ; then
314
+ add_warning 1 " Commit message contains inappropriate language. Avoid using abusive words"
315
+ fi
295
316
}
296
317
297
318
unset GREP_OPTIONS
0 commit comments