util/lint/checkpatch.pl: Update the check of repeated words
Update to v5.18-2 version. Signed-off-by: Elyes Haouas <ehaouas@noos.fr> Change-Id: I7f5e597bb76e1b9feeb2d6ea290626f45e9fe6c0 Reviewed-on: https://review.coreboot.org/c/coreboot/+/63577 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin L Roth <martinroth@google.com>
This commit is contained in:
parent
f62a98939d
commit
84083a27aa
|
@ -708,6 +708,8 @@ our @mode_permission_funcs = (
|
||||||
["__ATTR", 2],
|
["__ATTR", 2],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
|
||||||
|
|
||||||
#Create a search pattern for all these functions to speed up a loop below
|
#Create a search pattern for all these functions to speed up a loop below
|
||||||
our $mode_perms_search = "";
|
our $mode_perms_search = "";
|
||||||
foreach my $entry (@mode_permission_funcs) {
|
foreach my $entry (@mode_permission_funcs) {
|
||||||
|
@ -943,6 +945,13 @@ our $declaration_macros = qr{(?x:
|
||||||
(?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
|
(?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
|
||||||
)};
|
)};
|
||||||
|
|
||||||
|
our %allow_repeated_words = (
|
||||||
|
add => '',
|
||||||
|
added => '',
|
||||||
|
bad => '',
|
||||||
|
be => '',
|
||||||
|
);
|
||||||
|
|
||||||
sub deparenthesize {
|
sub deparenthesize {
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
return "" if (!defined($string));
|
return "" if (!defined($string));
|
||||||
|
@ -3000,6 +3009,59 @@ sub process {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# check for repeated words separated by a single space
|
||||||
|
# avoid false positive from list command eg, '-rw-r--r-- 1 root root'
|
||||||
|
if (($rawline =~ /^\+/ || $in_commit_log) &&
|
||||||
|
$rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) {
|
||||||
|
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 (lc($first) ne lc($second));
|
||||||
|
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$/);
|
||||||
|
next if (index(" \t.,;?!", $end_char) == -1);
|
||||||
|
|
||||||
|
# avoid repeating hex occurrences like 'ff ff fe 09 ...'
|
||||||
|
if ($first =~ /\b[0-9a-f]{2,}\b/i) {
|
||||||
|
next if (!exists($allow_repeated_words{lc($first)}));
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
# ignore non-hunk lines and lines being removed
|
||||||
next if (!$hunk_line || $line =~ /^-/);
|
next if (!$hunk_line || $line =~ /^-/);
|
||||||
|
|
Loading…
Reference in New Issue