lkml.org 
[lkml]   [2020]   [Oct]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH v3] checkpatch: add new exception to repeated word check
From
Date
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) {

\
 
 \ /
  Last update: 2020-10-17 09:29    [W:0.064 / U:0.212 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site