From patchwork Tue Jan 31 20:15:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 92998 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2101997qgi; Tue, 31 Jan 2017 12:16:07 -0800 (PST) X-Received: by 10.28.146.207 with SMTP id u198mr19270673wmd.36.1485893767187; Tue, 31 Jan 2017 12:16:07 -0800 (PST) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id 196si18507800wmw.120.2017.01.31.12.16.06; Tue, 31 Jan 2017 12:16:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ti.com Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7AA314B636; Tue, 31 Jan 2017 21:16:05 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HT2M_VsBpg3r; Tue, 31 Jan 2017 21:16:05 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 29A124B5B7; Tue, 31 Jan 2017 21:16:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D5F5F4B5BB for ; Tue, 31 Jan 2017 21:16:01 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2VLSbEW1lulj for ; Tue, 31 Jan 2017 21:16:01 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80]) by theia.denx.de (Postfix) with ESMTPS id 4D1534B5A1 for ; Tue, 31 Jan 2017 21:15:57 +0100 (CET) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id v0VKFsMN021144; Tue, 31 Jan 2017 14:15:54 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v0VKFsbt024772; Tue, 31 Jan 2017 14:15:54 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.294.0; Tue, 31 Jan 2017 14:15:54 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v0VKFsHm028027; Tue, 31 Jan 2017 14:15:54 -0600 Received: from localhost (a0272616local.dhcp.ti.com [172.22.160.29]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id v0VKFs312173; Tue, 31 Jan 2017 14:15:54 -0600 (CST) From: Dan Murphy To: Date: Tue, 31 Jan 2017 14:15:53 -0600 Message-ID: <1485893753-29434-2-git-send-email-dmurphy@ti.com> X-Mailer: git-send-email 2.7.2.333.g70bd996 In-Reply-To: <1485893753-29434-1-git-send-email-dmurphy@ti.com> References: <1485893753-29434-1-git-send-email-dmurphy@ti.com> MIME-Version: 1.0 Cc: trini@konsulko.com Subject: [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- scripts/checkpatch.pl | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) -- 2.11.0.rc0.7.gbe5a750 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot Reviewed-by: Tom Rini diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 84f57566fd..3afc870f0f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7,9 +7,12 @@ use strict; use POSIX; +use File::Basename; +use Cwd 'abs_path'; my $P = $0; $P =~ s@.*/@@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 =~ /^-/);