[Linux-kernel-mentees] [PATCH] checkpatch: add new exceptions to repeated word check

Dwaipayan Ray dwaipayanray1 at gmail.com
Fri Oct 16 18:16:13 UTC 2020


Recently, commit 4f6ad8aa1eac ("checkpatch: move repeated word test")
moved the repeated word test to check for more file types. But after
this, if checkpatch.pl is run on MAINTAINERS, it generates several
new warnings of the type:

WARNING: Possible repeated word: 'git'

For example:
WARNING: Possible repeated word: 'git'
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.git

So, the pattern "git git://..." is a false positive in this case.

There are several other combinations which may produce a wrong
warning message, such as "@size size", "Begin; begin", etc.

Extend repeated word check to compare the characters before and
after the word matches. If the preceding or succeeding character
belongs to the exception list, the warning is avoided.

Suggested-by: Joe Perches <joe at perches.com>
Suggested-by: Lukas Bulwahn <lukas.bulwahn at gmail.com>
Signed-off-by: Dwaipayan Ray <dwaipayanray1 at gmail.com>
---
 scripts/checkpatch.pl | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f1a4e61917eb..82497a71ac96 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -595,6 +595,7 @@ our @mode_permission_funcs = (
 );
 
 my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
+my $punctuation_chars = '[,:;@\.\-]';
 
 #Create a search pattern for all these functions to speed up a loop below
 our $mode_perms_search = "";
@@ -3065,6 +3066,21 @@ sub process {
 				next if ($first ne $second);
 				next if ($first eq 'long');
 
+				# check for character before and after the word matches
+				my $ca_first = substr($rawline, $-[1]-1, 1);
+				my $cb_first = substr($rawline, $+[1], 1);
+				my $ca_second = substr($rawline, $-[2]-1, 1);
+				my $cb_second = substr($rawline, $+[2], 1);
+
+				if ($ca_first ne $ca_second || $cb_first ne $cb_second) {
+					if ($ca_first =~ /$punctuation_chars/ ||
+					    $ca_second =~ /$punctuation_chars/ ||
+					    $cb_first =~ /$punctuation_chars/ ||
+					    $cb_second =~ /$punctuation_chars/) {
+						next;
+					}
+				}
+
 				if (WARN("REPEATED_WORD",
 					 "Possible repeated word: '$first'\n" . $herecurr) &&
 				    $fix) {
-- 
2.27.0



More information about the Linux-kernel-mentees mailing list