mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-30 08:07:59 +00:00
checkpatch: Port spelling to checkpatch
Pick commit 66b47b4a9dad0 checkpatch: look for common misspellings from the Linux kernel for spelling check from Kees Cook In addition pulled in additional changes commit ebfd7d6237531 checkpatch: add optional --codespell dictionary to find more typos from the Linux kernel for codespell from Joe Perches commit f1a63678554f8 checkpatch: remove local from codespell path from the Linux kernel for dictionary path from Maxim Uvarov Signed-off-by: Dan Murphy <dmurphy@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
parent
b569048357
commit
c10e0f5b38
1 changed files with 81 additions and 0 deletions
|
@ -7,9 +7,12 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
use File::Basename;
|
||||||
|
use Cwd 'abs_path';
|
||||||
|
|
||||||
my $P = $0;
|
my $P = $0;
|
||||||
$P =~ s@.*/@@g;
|
$P =~ s@.*/@@g;
|
||||||
|
my $D = dirname(abs_path($P));
|
||||||
|
|
||||||
my $V = '0.32';
|
my $V = '0.32';
|
||||||
|
|
||||||
|
@ -42,6 +45,9 @@ my $configuration_file = ".checkpatch.conf";
|
||||||
my $max_line_length = 80;
|
my $max_line_length = 80;
|
||||||
my $ignore_perl_version = 0;
|
my $ignore_perl_version = 0;
|
||||||
my $minimum_perl_version = 5.10.0;
|
my $minimum_perl_version = 5.10.0;
|
||||||
|
my $spelling_file = "$D/spelling.txt";
|
||||||
|
my $codespell = 0;
|
||||||
|
my $codespellfile = "/usr/share/codespell/dictionary.txt";
|
||||||
|
|
||||||
sub help {
|
sub help {
|
||||||
my ($exitcode) = @_;
|
my ($exitcode) = @_;
|
||||||
|
@ -82,6 +88,9 @@ Options:
|
||||||
file. It's your fault if there's no backup or git
|
file. It's your fault if there's no backup or git
|
||||||
--ignore-perl-version override checking of perl version. expect
|
--ignore-perl-version override checking of perl version. expect
|
||||||
runtime errors.
|
runtime errors.
|
||||||
|
--codespell Use the codespell dictionary for spelling/typos
|
||||||
|
(default:/usr/local/share/codespell/dictionary.txt)
|
||||||
|
--codespellfile Use this codespell dictionary
|
||||||
-h, --help, --version display this help and exit
|
-h, --help, --version display this help and exit
|
||||||
|
|
||||||
When FILE is - read standard input.
|
When FILE is - read standard input.
|
||||||
|
@ -139,6 +148,8 @@ GetOptions(
|
||||||
'ignore-perl-version!' => \$ignore_perl_version,
|
'ignore-perl-version!' => \$ignore_perl_version,
|
||||||
'debug=s' => \%debug,
|
'debug=s' => \%debug,
|
||||||
'test-only=s' => \$tst_only,
|
'test-only=s' => \$tst_only,
|
||||||
|
'codespell!' => \$codespell,
|
||||||
|
'codespellfile=s' => \$codespellfile,
|
||||||
'h|help' => \$help,
|
'h|help' => \$help,
|
||||||
'version' => \$help
|
'version' => \$help
|
||||||
) or help(1);
|
) or help(1);
|
||||||
|
@ -387,6 +398,56 @@ our $allowed_asm_includes = qr{(?x:
|
||||||
)};
|
)};
|
||||||
# memory.h: ARM has a custom one
|
# memory.h: ARM has a custom one
|
||||||
|
|
||||||
|
# Load common spelling mistakes and build regular expression list.
|
||||||
|
my $misspellings;
|
||||||
|
my %spelling_fix;
|
||||||
|
|
||||||
|
if (open(my $spelling, '<', $spelling_file)) {
|
||||||
|
while (<$spelling>) {
|
||||||
|
my $line = $_;
|
||||||
|
|
||||||
|
$line =~ s/\s*\n?$//g;
|
||||||
|
$line =~ s/^\s*//g;
|
||||||
|
|
||||||
|
next if ($line =~ m/^\s*#/);
|
||||||
|
next if ($line =~ m/^\s*$/);
|
||||||
|
|
||||||
|
my ($suspect, $fix) = split(/\|\|/, $line);
|
||||||
|
|
||||||
|
$spelling_fix{$suspect} = $fix;
|
||||||
|
}
|
||||||
|
close($spelling);
|
||||||
|
} else {
|
||||||
|
warn "No typos will be found - file '$spelling_file': $!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($codespell) {
|
||||||
|
if (open(my $spelling, '<', $codespellfile)) {
|
||||||
|
while (<$spelling>) {
|
||||||
|
my $line = $_;
|
||||||
|
|
||||||
|
$line =~ s/\s*\n?$//g;
|
||||||
|
$line =~ s/^\s*//g;
|
||||||
|
|
||||||
|
next if ($line =~ m/^\s*#/);
|
||||||
|
next if ($line =~ m/^\s*$/);
|
||||||
|
next if ($line =~ m/, disabled/i);
|
||||||
|
|
||||||
|
$line =~ s/,.*$//;
|
||||||
|
|
||||||
|
my ($suspect, $fix) = split(/->/, $line);
|
||||||
|
|
||||||
|
$spelling_fix{$suspect} = $fix;
|
||||||
|
}
|
||||||
|
close($spelling);
|
||||||
|
} else {
|
||||||
|
warn "No codespell typos will be found - file '$codespellfile': $!\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
|
||||||
|
|
||||||
|
|
||||||
sub build_types {
|
sub build_types {
|
||||||
my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
|
my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
|
||||||
my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
|
my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
|
||||||
|
@ -528,6 +589,8 @@ my @rawlines = ();
|
||||||
my @lines = ();
|
my @lines = ();
|
||||||
my @fixed = ();
|
my @fixed = ();
|
||||||
my $vname;
|
my $vname;
|
||||||
|
my $fixlinenr = -1;
|
||||||
|
|
||||||
for my $filename (@ARGV) {
|
for my $filename (@ARGV) {
|
||||||
my $FILE;
|
my $FILE;
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
@ -1950,6 +2013,24 @@ sub process {
|
||||||
"8-bit UTF-8 used in possible commit log\n" . $herecurr);
|
"8-bit UTF-8 used in possible commit log\n" . $herecurr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check for various typo / spelling mistakes
|
||||||
|
if (defined($misspellings) &&
|
||||||
|
($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
|
||||||
|
while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
|
||||||
|
my $typo = $1;
|
||||||
|
my $typo_fix = $spelling_fix{lc($typo)};
|
||||||
|
$typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
|
||||||
|
$typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
|
||||||
|
my $msg_type = \&WARN;
|
||||||
|
$msg_type = \&CHK if ($file);
|
||||||
|
if (&{$msg_type}("TYPO_SPELLING",
|
||||||
|
"'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
|
||||||
|
$fix) {
|
||||||
|
$fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# 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…
Add table
Reference in a new issue