From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88602C433DF for ; Sat, 17 Oct 2020 05:41:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5283B20720 for ; Sat, 17 Oct 2020 05:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436586AbgJQFlJ (ORCPT ); Sat, 17 Oct 2020 01:41:09 -0400 Received: from smtprelay0191.hostedemail.com ([216.40.44.191]:36530 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2406672AbgJQFlI (ORCPT ); Sat, 17 Oct 2020 01:41:08 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 60B3E180A8142; Sat, 17 Oct 2020 05:41:07 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: art22_2a0f92227223 X-Filterd-Recvd-Size: 3801 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf01.hostedemail.com (Postfix) with ESMTPA; Sat, 17 Oct 2020 05:41:06 +0000 (UTC) Message-ID: Subject: Re: [PATCH v3] checkpatch: add new exception to repeated word check From: Joe Perches To: Dwaipayan Ray Cc: linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, lukas.bulwahn@gmail.com Date: Fri, 16 Oct 2020 22:41:05 -0700 In-Reply-To: <20201017052243.17095-1-dwaipayanray1@gmail.com> References: <20201017052243.17095-1-dwaipayanray1@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2020-10-17 at 10:52 +0530, Dwaipayan Ray 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. > > Link: https://lore.kernel.org/linux-kernel-mentees/81b6a0bb2c7b9256361573f7a13201ebcd4876f1.camel@perches.com/ > Suggested-by: Joe Perches > Suggested-by: Lukas Bulwahn > Signed-off-by: Dwaipayan Ray > --- > scripts/checkpatch.pl | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index f1a4e61917eb..89430dfd6652 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 $exclude_chars = '[^\.\,\+\s]'; Why include a + character here? > #Create a search pattern for all these functions to speed up a loop below > our $mode_perms_search = ""; > @@ -3056,15 +3057,27 @@ sub process { > > my $first = $1; > my $second = $2; > - > + my $start_pos = $-[1]; > + my $end_pos = $+[2]; > if ($first =~ /(?:struct|union|enum)/) { > pos($rawline) += length($first) + length($second) + 1; > next; > } > > - next if ($first ne $second); > + next if (lc($first) ne lc($second)); > next if ($first eq 'long'); > > + # check for character before and after the word matches > + my $start_char = ''; > + my $end_char = ''; > + $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > 0); > + $end_char = substr($rawline, $end_pos, 1) if ($end_pos <= length($rawline)); substr uses index 0, so I believe the if should be < > + > + if ($start_char =~ /^$exclude_chars$/ || > + $end_char =~ /^$exclude_chars$/) { > + next; > + } Please use "next if (test);" to be similar to the other uses above. And this doesn't work on end of phrase or sentence. ie: "my sentence is is, a duplicate word word." so $end_char could be a comma or a period. so likely the $end_char test should be !~ What is the reason to add and use $exclude_chars?