Skip to content

Commit

Permalink
checkpatch: move repeated word test
Browse files Browse the repository at this point in the history
Currently this test only works on .[ch] files.

Move the test to check more file types and the commit log.

Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Link: http:https://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Oct 16, 2020
1 parent 3e89ad8 commit 310cd06
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,42 @@ sub process {
}
}

# check for repeated words separated by a single space
if ($rawline =~ /^\+/ || $in_commit_log) {
while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {

my $first = $1;
my $second = $2;

if ($first =~ /(?:struct|union|enum)/) {
pos($rawline) += length($first) + length($second) + 1;
next;
}

next if ($first ne $second);
next if ($first eq 'long');

if (WARN("REPEATED_WORD",
"Possible repeated word: '$first'\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
}
}

# if it's a repeated word on consecutive lines in a comment block
if ($prevline =~ /$;+\s*$/ &&
$prevrawline =~ /($word_pattern)\s*$/) {
my $last_word = $1;
if ($rawline =~ /^\+\s*\*\s*$last_word /) {
if (WARN("REPEATED_WORD",
"Possible repeated word: '$last_word'\n" . $hereprev) &&
$fix) {
$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
}
}
}
}

# ignore non-hunk lines and lines being removed
next if (!$hunk_line || $line =~ /^-/);

Expand Down Expand Up @@ -3314,42 +3350,6 @@ sub process {
}
}

# check for repeated words separated by a single space
if ($rawline =~ /^\+/) {
while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {

my $first = $1;
my $second = $2;

if ($first =~ /(?:struct|union|enum)/) {
pos($rawline) += length($first) + length($second) + 1;
next;
}

next if ($first ne $second);
next if ($first eq 'long');

if (WARN("REPEATED_WORD",
"Possible repeated word: '$first'\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
}
}

# if it's a repeated word on consecutive lines in a comment block
if ($prevline =~ /$;+\s*$/ &&
$prevrawline =~ /($word_pattern)\s*$/) {
my $last_word = $1;
if ($rawline =~ /^\+\s*\*\s*$last_word /) {
if (WARN("REPEATED_WORD",
"Possible repeated word: '$last_word'\n" . $hereprev) &&
$fix) {
$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
}
}
}
}

# check for space before tabs.
if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Expand Down

0 comments on commit 310cd06

Please sign in to comment.