* [U-Boot] [PATCH 0/1] Introducing Spell check for checkpatch from LK
@ 2017-01-31 20:15 Dan Murphy
2017-01-31 20:15 ` [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch Dan Murphy
0 siblings, 1 reply; 4+ messages in thread
From: Dan Murphy @ 2017-01-31 20:15 UTC (permalink / raw)
To: u-boot
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(+)
--
2.11.0.rc0.7.gbe5a750
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch
2017-01-31 20:15 [U-Boot] [PATCH 0/1] Introducing Spell check for checkpatch from LK Dan Murphy
@ 2017-01-31 20:15 ` Dan Murphy
2017-02-03 16:52 ` Tom Rini
2017-02-09 3:02 ` [U-Boot] [U-Boot,1/1] " Tom Rini
0 siblings, 2 replies; 4+ messages in thread
From: Dan Murphy @ 2017-01-31 20:15 UTC (permalink / raw)
To: 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 <dmurphy@ti.com>
---
scripts/checkpatch.pl | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
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 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 =~ /^-/);
--
2.11.0.rc0.7.gbe5a750
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch
2017-01-31 20:15 ` [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch Dan Murphy
@ 2017-02-03 16:52 ` Tom Rini
2017-02-09 3:02 ` [U-Boot] [U-Boot,1/1] " Tom Rini
1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2017-02-03 16:52 UTC (permalink / raw)
To: u-boot
On Tue, Jan 31, 2017 at 02:15:53PM -0600, Dan Murphy wrote:
> 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>
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [U-Boot,1/1] checkpatch: Port spelling to checkpatch
2017-01-31 20:15 ` [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch Dan Murphy
2017-02-03 16:52 ` Tom Rini
@ 2017-02-09 3:02 ` Tom Rini
1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2017-02-09 3:02 UTC (permalink / raw)
To: u-boot
On Tue, Jan 31, 2017 at 02:15:53PM -0600, Dan Murphy wrote:
> 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>
Applied to u-boot/master, thanks!
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-09 3:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-31 20:15 [U-Boot] [PATCH 0/1] Introducing Spell check for checkpatch from LK Dan Murphy
2017-01-31 20:15 ` [U-Boot] [PATCH 1/1] checkpatch: Port spelling to checkpatch Dan Murphy
2017-02-03 16:52 ` Tom Rini
2017-02-09 3:02 ` [U-Boot] [U-Boot,1/1] " Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.