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=-11.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,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 60933C433DF for ; Sat, 17 Oct 2020 15:54:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24CFB2074A for ; Sat, 17 Oct 2020 15:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437594AbgJQPyi (ORCPT ); Sat, 17 Oct 2020 11:54:38 -0400 Received: from smtprelay0198.hostedemail.com ([216.40.44.198]:33272 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2436623AbgJQPyh (ORCPT ); Sat, 17 Oct 2020 11:54:37 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 47FCB18224504; Sat, 17 Oct 2020 15:54:36 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: nest32_481265327227 X-Filterd-Recvd-Size: 3377 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf13.hostedemail.com (Postfix) with ESMTPA; Sat, 17 Oct 2020 15:54:35 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4] 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: Sat, 17 Oct 2020 08:54:34 -0700 In-Reply-To: <20201017075131.47566-1-dwaipayanray1@gmail.com> References: <20201017075131.47566-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 13:21 +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. Not true. This excludes any non-space character before the first word and excludes space or punctuation after the second word. This also adds case insensitive word matching. > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -3052,19 +3052,30 @@ sub process { > > # check for repeated words separated by a single space > if ($rawline =~ /^\+/ || $in_commit_log) { > + pos($rawline) = 1 if (!$in_commit_log); > while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) { > > 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)); case-insensitive matching > 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 > ($in_commit_log? 0 : 1)); > + $end_char = substr($rawline, $end_pos, 1) if ($end_pos < length($rawline)); > + > + next if ($start_char =~ /^\S$/); non-space > + next if ($end_char !~ /^[\.\,\;\?\!\s]?$/); space or punctuation. trivia: I believe using index would be ~50% faster than !~ here Perhaps more readable too. next if (index(" \t.,;?!", $end_char) >= 0); > + > if (WARN("REPEATED_WORD", > "Possible repeated word: '$first'\n" . $herecurr) && > $fix) {