Skip to content

Commit 310cd06

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: move repeated word test
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 <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/r/180b3b5677771c902b2e2f7a2b7090ede65fe004.camel@perches.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3e89ad8 commit 310cd06

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,42 @@ sub process {
29912991
}
29922992
}
29932993

2994+
# check for repeated words separated by a single space
2995+
if ($rawline =~ /^\+/ || $in_commit_log) {
2996+
while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
2997+
2998+
my $first = $1;
2999+
my $second = $2;
3000+
3001+
if ($first =~ /(?:struct|union|enum)/) {
3002+
pos($rawline) += length($first) + length($second) + 1;
3003+
next;
3004+
}
3005+
3006+
next if ($first ne $second);
3007+
next if ($first eq 'long');
3008+
3009+
if (WARN("REPEATED_WORD",
3010+
"Possible repeated word: '$first'\n" . $herecurr) &&
3011+
$fix) {
3012+
$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
3013+
}
3014+
}
3015+
3016+
# if it's a repeated word on consecutive lines in a comment block
3017+
if ($prevline =~ /$;+\s*$/ &&
3018+
$prevrawline =~ /($word_pattern)\s*$/) {
3019+
my $last_word = $1;
3020+
if ($rawline =~ /^\+\s*\*\s*$last_word /) {
3021+
if (WARN("REPEATED_WORD",
3022+
"Possible repeated word: '$last_word'\n" . $hereprev) &&
3023+
$fix) {
3024+
$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
3025+
}
3026+
}
3027+
}
3028+
}
3029+
29943030
# ignore non-hunk lines and lines being removed
29953031
next if (!$hunk_line || $line =~ /^-/);
29963032

@@ -3314,42 +3350,6 @@ sub process {
33143350
}
33153351
}
33163352

3317-
# check for repeated words separated by a single space
3318-
if ($rawline =~ /^\+/) {
3319-
while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
3320-
3321-
my $first = $1;
3322-
my $second = $2;
3323-
3324-
if ($first =~ /(?:struct|union|enum)/) {
3325-
pos($rawline) += length($first) + length($second) + 1;
3326-
next;
3327-
}
3328-
3329-
next if ($first ne $second);
3330-
next if ($first eq 'long');
3331-
3332-
if (WARN("REPEATED_WORD",
3333-
"Possible repeated word: '$first'\n" . $herecurr) &&
3334-
$fix) {
3335-
$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
3336-
}
3337-
}
3338-
3339-
# if it's a repeated word on consecutive lines in a comment block
3340-
if ($prevline =~ /$;+\s*$/ &&
3341-
$prevrawline =~ /($word_pattern)\s*$/) {
3342-
my $last_word = $1;
3343-
if ($rawline =~ /^\+\s*\*\s*$last_word /) {
3344-
if (WARN("REPEATED_WORD",
3345-
"Possible repeated word: '$last_word'\n" . $hereprev) &&
3346-
$fix) {
3347-
$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
3348-
}
3349-
}
3350-
}
3351-
}
3352-
33533353
# check for space before tabs.
33543354
if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
33553355
my $herevet = "$here\n" . cat_vet($rawline) . "\n";

0 commit comments

Comments
 (0)