summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl38
1 files changed, 34 insertions, 4 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c061a63afa20..6b79beb2751d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -47,6 +47,8 @@ my $ignore_perl_version = 0;
47my $minimum_perl_version = 5.10.0; 47my $minimum_perl_version = 5.10.0;
48my $min_conf_desc_length = 4; 48my $min_conf_desc_length = 4;
49my $spelling_file = "$D/spelling.txt"; 49my $spelling_file = "$D/spelling.txt";
50my $codespell = 0;
51my $codespellfile = "/usr/local/share/codespell/dictionary.txt";
50 52
51sub help { 53sub help {
52 my ($exitcode) = @_; 54 my ($exitcode) = @_;
@@ -88,6 +90,9 @@ Options:
88 file. It's your fault if there's no backup or git 90 file. It's your fault if there's no backup or git
89 --ignore-perl-version override checking of perl version. expect 91 --ignore-perl-version override checking of perl version. expect
90 runtime errors. 92 runtime errors.
93 --codespell Use the codespell dictionary for spelling/typos
94 (default:/usr/local/share/codespell/dictionary.txt)
95 --codespellfile Use this codespell dictionary
91 -h, --help, --version display this help and exit 96 -h, --help, --version display this help and exit
92 97
93When FILE is - read standard input. 98When FILE is - read standard input.
@@ -146,6 +151,8 @@ GetOptions(
146 'ignore-perl-version!' => \$ignore_perl_version, 151 'ignore-perl-version!' => \$ignore_perl_version,
147 'debug=s' => \%debug, 152 'debug=s' => \%debug,
148 'test-only=s' => \$tst_only, 153 'test-only=s' => \$tst_only,
154 'codespell!' => \$codespell,
155 'codespellfile=s' => \$codespellfile,
149 'h|help' => \$help, 156 'h|help' => \$help,
150 'version' => \$help 157 'version' => \$help
151) or help(1); 158) or help(1);
@@ -449,7 +456,6 @@ my $misspellings;
449my %spelling_fix; 456my %spelling_fix;
450 457
451if (open(my $spelling, '<', $spelling_file)) { 458if (open(my $spelling, '<', $spelling_file)) {
452 my @spelling_list;
453 while (<$spelling>) { 459 while (<$spelling>) {
454 my $line = $_; 460 my $line = $_;
455 461
@@ -461,15 +467,39 @@ if (open(my $spelling, '<', $spelling_file)) {
461 467
462 my ($suspect, $fix) = split(/\|\|/, $line); 468 my ($suspect, $fix) = split(/\|\|/, $line);
463 469
464 push(@spelling_list, $suspect);
465 $spelling_fix{$suspect} = $fix; 470 $spelling_fix{$suspect} = $fix;
466 } 471 }
467 close($spelling); 472 close($spelling);
468 $misspellings = join("|", @spelling_list);
469} else { 473} else {
470 warn "No typos will be found - file '$spelling_file': $!\n"; 474 warn "No typos will be found - file '$spelling_file': $!\n";
471} 475}
472 476
477if ($codespell) {
478 if (open(my $spelling, '<', $codespellfile)) {
479 while (<$spelling>) {
480 my $line = $_;
481
482 $line =~ s/\s*\n?$//g;
483 $line =~ s/^\s*//g;
484
485 next if ($line =~ m/^\s*#/);
486 next if ($line =~ m/^\s*$/);
487 next if ($line =~ m/, disabled/i);
488
489 $line =~ s/,.*$//;
490
491 my ($suspect, $fix) = split(/->/, $line);
492
493 $spelling_fix{$suspect} = $fix;
494 }
495 close($spelling);
496 } else {
497 warn "No codespell typos will be found - file '$codespellfile': $!\n";
498 }
499}
500
501$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
502
473sub build_types { 503sub build_types {
474 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; 504 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
475 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; 505 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
@@ -2305,7 +2335,7 @@ sub process {
2305# Check for various typo / spelling mistakes 2335# Check for various typo / spelling mistakes
2306 if (defined($misspellings) && 2336 if (defined($misspellings) &&
2307 ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { 2337 ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
2308 while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { 2338 while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
2309 my $typo = $1; 2339 my $typo = $1;
2310 my $typo_fix = $spelling_fix{lc($typo)}; 2340 my $typo_fix = $spelling_fix{lc($typo)};
2311 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); 2341 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);