Introducing Spell check for checkpatch from LK
cover Introducing Spell check for checkpatch from LK
All
This is the codespell and codespellfile code from the Linux kernel. I am not sure if I have formatted the commit message properly enough to give the original authors of the code the credit they deserve.
I sited the patches I could find and had to add some additional variables that were part of other patches in which the codespell took advantage of.
Dan
Dan Murphy (1):
checkpatch: Port spelling to checkpatch
scripts/checkpatch.pl | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
Signature · 1 line
2.11.0.rc0.7.gbe5a750
PATCH 1/1 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
--- scripts/checkpatch.pl | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
scripts/checkpatch.pl +81 -0
@@ -7,9 +7,12 @@ use strict; use POSIX; +use File::Basename; +use Cwd 'abs_path'; my $P = $0; $P =~ s at .*/@@g; +my $D = dirname(abs_path($P)); my $V = '0.32';
@@ -42,6 +45,9 @@ my $configuration_file = ".checkpatch.conf"; my $max_line_length = 80; my $ignore_perl_version = 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 { my ($exitcode) = @_;
@@ -82,6 +88,9 @@ Options: file. It's your fault if there's no backup or git --ignore-perl-version override checking of perl version. expect 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 When FILE is - read standard input.
@@ -139,6 +148,8 @@ GetOptions( 'ignore-perl-version!' => \$ignore_perl_version, 'debug=s' => \%debug, 'test-only=s' => \$tst_only, + 'codespell!' => \$codespell, + 'codespellfile=s' => \$codespellfile, 'h|help' => \$help, 'version' => \$help ) or help(1);
@@ -387,6 +398,56 @@ our $allowed_asm_includes = qr{(?x: )}; # 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 { my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
@@ -528,6 +589,8 @@ my @rawlines = (); my @lines = (); my @fixed = (); my $vname; +my $fixlinenr = -1; + for my $filename (@ARGV) { my $FILE; if ($file) {
@@ -1950,6 +2013,24 @@ sub process { "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 next if (!$hunk_line || $line =~ /^-/);
Signature · 1 line
2.11.0.rc0.7.gbe5a750
PATCH 1/1 checkpatch: Port spelling to checkpatch
Quoted 11 lines · Dan Murphy
Pick commit
66b47b4a9dad0checkpatch: look for common misspellings from the Linux kernel for spelling check from Kees CookIn addition pulled in additional changes
commitebfd7d6237531checkpatch: add optional --codespell dictionary to find more typos from the Linux kernel for codespell from Joe Perchescommit
f1a63678554f8checkpatch: remove local from codespell path from the Linux kernel for dictionary path from Maxim UvarovSigned-off-by Dan Murphy <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170203/b9df606d/attachment.sig>
PATCH 1/1 checkpatch: Port spelling to checkpatch
In reply to Dan MurphyQuoted 7 lines · Dan Murphy
Pick commit
66b47b4a9dad0checkpatch: look for common misspellings from the Linux kernel for spelling check from Kees CookIn addition pulled in additional changes
commitebfd7d6237531checkpatch: add optional --codespell dictionary to find more typos from the Linux kernel for codespell from Joe Perches
Quoted 5 lines
commit
f1a63678554f8checkpatch: remove local from codespell path from the Linux kernel for dictionary path from Maxim UvarovSigned-off-by Dan Murphy <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170208/6398bdef/attachment.sig>