checkpatch: add new exceptions to repeated word check
PATCH 1/1 checkpatch: add new exceptions to repeated word check
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.
--- scripts/checkpatch.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
scripts/checkpatch.pl +16 -0
@@ -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) {
Signature · 6 lines
2.27.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 63 lines · Dwaipayan Ray
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 onMAINTAINERS, it generates several new warnings of the type:WARNING: Possible repeated word: 'git'
For example:
WARNING: Possible repeated word: 'git'
+T: gitgit://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.gitSo, 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 <[email protected]>Suggested-by Lukas Bulwahn <[email protected]>Signed-off-by Dwaipayan Ray <[email protected]>--- scripts/checkpatch.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)scripts/checkpatch.pl +16
-1@@ -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) { --
Quoted 2 lines
2.27.0
Hi,
This patch is followed from the discussion at
https://lore.kernel.org/linux-kernel-mentees/[email protected]/
, where Joe suggested that instead of hard coding the particular words, we can check the surrounding characters instead for punctuations and ingore them.
Please let me know if any changes are needed.
Thanks,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
I think for this feature you do not to need to send it first to me and then to lkml.
Just continue the discussion directlyon lkml.
Lukas
Quoted 87 lines · Dwaipayan Ray
Quoted 33 lines · Dwaipayan Ray
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 onMAINTAINERS, it generates several new warnings of the type:WARNING: Possible repeated word: 'git'
For example:
WARNING: Possible repeated word: 'git'
+T: gitgit://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.gitSo, 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 <[email protected]>Suggested-by Lukas Bulwahn <[email protected]>Signed-off-by Dwaipayan Ray <[email protected]>--- scripts/checkpatch.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)scripts/checkpatch.pl +0
-0scripts/checkpatch.pl our @mode_permission_funcs = ( · line 600
Quoted 6 lines
scripts/checkpatch.pl +1
-0@@ -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 loopbelow
scripts/checkpatch.pl sub process { · line 3069
Quoted 6 lines
scripts/checkpatch.pl +1
-0our $mode_perms_search = "";@@ -3065,6 +3066,21 @@ sub process { next if ($first ne $second); next if ($first eq 'long'); + # check for character before and afterthe word matches
scripts/checkpatch.pl sub process { · line 3070
Quoted 1 line
scripts/checkpatch.pl +1
-0+ my $ca_first = substr($rawline, $-[1]-1,1);
scripts/checkpatch.pl sub process { · line 3071
Quoted 1 line
scripts/checkpatch.pl +1
-0+ my $cb_first = substr($rawline, $+[1],1);
scripts/checkpatch.pl sub process { · line 3072
Quoted 1 line
scripts/checkpatch.pl +1
-0+ my $ca_second = substr($rawline,$-[2]-1, 1);
scripts/checkpatch.pl sub process { · line 3073
Quoted 1 line
scripts/checkpatch.pl +1
-0+ my $cb_second = substr($rawline, $+[2],1);
scripts/checkpatch.pl sub process { · line 3075
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ + if ($ca_first ne $ca_second || $cb_firstne $cb_second) {
scripts/checkpatch.pl sub process { · line 3076
Quoted 1 line
scripts/checkpatch.pl +1
-0+ if ($ca_first =~/$punctuation_chars/ ||
scripts/checkpatch.pl sub process { · line 3077
Quoted 1 line
scripts/checkpatch.pl +1
-0+ $ca_second =~/$punctuation_chars/ ||
scripts/checkpatch.pl sub process { · line 3078
Quoted 1 line
scripts/checkpatch.pl +1
-0+ $cb_first =~/$punctuation_chars/ ||
scripts/checkpatch.pl sub process { · line 3079
Quoted 1 line
scripts/checkpatch.pl +1
-0+ $cb_second =~/$punctuation_chars/) {
scripts/checkpatch.pl sub process {
Quoted 6 lines
scripts/checkpatch.pl +4
-0+ next; + } + } + if (WARN("REPEATED_WORD", "Possible repeated word:'$first'\n" . $herecurr) &&
Quoted 4 lines
scripts/checkpatch.pl +0
-1$fix) { --2.27.0
Hi,
This patch is followed from the discussion athttps://lore.kernel.org/linux-kernel-mentees/[email protected]/
, where Joe suggested that instead of hard coding the particular words, we can check the surrounding characters instead for punctuations and ingore them.
Quoted 5 lines
Please let me know if any changes are needed.
Thanks,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees