Linux Kernel Mentees Archive on lore.kernel.org
 help / color / Atom feed
* [Linux-kernel-mentees] [PATCH] checkpatch: add new exceptions to repeated word check
@ 2020-10-16 18:16 Dwaipayan Ray
  2020-10-16 18:22 ` Dwaipayan Ray
  0 siblings, 1 reply; 3+ messages in thread
From: Dwaipayan Ray @ 2020-10-16 18:16 UTC (permalink / raw)
  To: lukas.bulwahn; +Cc: dwaipayanray1, linux-kernel-mentees

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@perches.com>
Suggested-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Dwaipayan Ray <dwaipayanray1@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

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] checkpatch: add new exceptions to repeated word check
  2020-10-16 18:16 [Linux-kernel-mentees] [PATCH] checkpatch: add new exceptions to repeated word check Dwaipayan Ray
@ 2020-10-16 18:22 ` Dwaipayan Ray
  2020-10-17  5:24   ` Lukas Bulwahn
  0 siblings, 1 reply; 3+ messages in thread
From: Dwaipayan Ray @ 2020-10-16 18:22 UTC (permalink / raw)
  To: Lukas Bulwahn; +Cc: linux-kernel-mentees

On Fri, Oct 16, 2020 at 11:46 PM Dwaipayan Ray <dwaipayanray1@gmail.com> wrote:
>
> 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@perches.com>
> Suggested-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Dwaipayan Ray <dwaipayanray1@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
>
Hi,
This patch is followed from the discussion at
https://lore.kernel.org/linux-kernel-mentees/7d8c7d80aa7b0524cca49a6dfe24e878bea6ab12.camel@perches.com/
, 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
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] checkpatch: add new exceptions to repeated word check
  2020-10-16 18:22 ` Dwaipayan Ray
@ 2020-10-17  5:24   ` Lukas Bulwahn
  0 siblings, 0 replies; 3+ messages in thread
From: Lukas Bulwahn @ 2020-10-17  5:24 UTC (permalink / raw)
  To: Dwaipayan Ray; +Cc: linux-kernel-mentees

[-- Attachment #1.1: Type: text/plain, Size: 3694 bytes --]

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

On Fr., 16. Okt. 2020 at 20:22, Dwaipayan Ray <dwaipayanray1@gmail.com>
wrote:

> On Fri, Oct 16, 2020 at 11:46 PM Dwaipayan Ray <dwaipayanray1@gmail.com>
> wrote:
> >
> > 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@perches.com>
> > Suggested-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> > Signed-off-by: Dwaipayan Ray <dwaipayanray1@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
> >
> Hi,
> This patch is followed from the discussion at
>
> https://lore.kernel.org/linux-kernel-mentees/7d8c7d80aa7b0524cca49a6dfe24e878bea6ab12.camel@perches.com/
> , 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.
>

[-- Attachment #1.2: Type: text/html, Size: 5857 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16 18:16 [Linux-kernel-mentees] [PATCH] checkpatch: add new exceptions to repeated word check Dwaipayan Ray
2020-10-16 18:22 ` Dwaipayan Ray
2020-10-17  5:24   ` Lukas Bulwahn

Linux Kernel Mentees Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kernel-mentees/0 linux-kernel-mentees/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kernel-mentees linux-kernel-mentees/ https://lore.kernel.org/linux-kernel-mentees \
		linux-kernel-mentees@lists.linuxfoundation.org linux-kernel-mentees@lists.linux-foundation.org
	public-inbox-index linux-kernel-mentees

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxfoundation.lists.linux-kernel-mentees


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git