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=-6.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 8EDB0C433DF for ; Sat, 17 Oct 2020 07:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4976F20758 for ; Sat, 17 Oct 2020 07:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437465AbgJQH23 (ORCPT ); Sat, 17 Oct 2020 03:28:29 -0400 Received: from smtprelay0090.hostedemail.com ([216.40.44.90]:57434 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2436550AbgJQH23 (ORCPT ); Sat, 17 Oct 2020 03:28:29 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id 55DD5100E7B40; Sat, 17 Oct 2020 07:28:28 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: dress26_2a0c37727223 X-Filterd-Recvd-Size: 2977 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 07:28:27 +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 , Lukas Bulwahn Date: Sat, 17 Oct 2020 00:28:25 -0700 In-Reply-To: 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 11:32 +0530, Dwaipayan Ray wrote: > > Why include a + character here? > > > Hi, > I tried it without + first, but then lines like > "The the repeated word." > didn't register a warning. > > I think checkpatch adds a + to the line when used on > files. Am not sure but my $rawline was: > +The the repeated word. The + is the first character of an added line in a patch. That's different from lines in a commit message so there needs to be an additional mechanism to strip the leading + when not !$in_commit_log. Add: pos($rawline) = 1 if (!$in_commit_log); and test the start position too --- scripts/checkpatch.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index fab38b493cef..99563b3d5a3e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3050,19 +3050,28 @@ 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)); next if ($first eq 'long'); + 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 (length($rawline) > $end_pos); + next if ($start_char =~ /^\S$/); + next if ($end_char !~ /^[\.\,\s]?$/); + if (WARN("REPEATED_WORD", "Possible repeated word: '$first'\n" . $herecurr) && $fix) {