diff options
| author | Joe Perches <joe@perches.com> | 2013-07-03 18:05:31 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:07:45 -0400 |
| commit | 3705ce5bcc1037b68e9d20f90ab50bc7f64edd00 (patch) | |
| tree | 3f5f6e5a5a749c88418e114a34ee85b9c99fad28 /scripts | |
| parent | 23f780c90496eb1cc158e862e7035c8468dfa052 (diff) | |
checkpatch: create an EXPERIMENTAL --fix option to correct patches
Some patches have simple defects in whitespace and formatting that
checkpatch could correct automatically. Attempt to do so.
Add a --fix option to create a "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
file that tries to use normal kernel style for some of these formatting
errors.
Add warnings against using this file without verifying the changes.
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 442 |
1 files changed, 354 insertions, 88 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ab39ceb38286..9696be57ea42 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -27,6 +27,7 @@ my $summary = 1; | |||
| 27 | my $mailback = 0; | 27 | my $mailback = 0; |
| 28 | my $summary_file = 0; | 28 | my $summary_file = 0; |
| 29 | my $show_types = 0; | 29 | my $show_types = 0; |
| 30 | my $fix = 0; | ||
| 30 | my $root; | 31 | my $root; |
| 31 | my %debug; | 32 | my %debug; |
| 32 | my %ignore_type = (); | 33 | my %ignore_type = (); |
| @@ -63,6 +64,11 @@ Options: | |||
| 63 | is all off) | 64 | is all off) |
| 64 | --test-only=WORD report only warnings/errors containing WORD | 65 | --test-only=WORD report only warnings/errors containing WORD |
| 65 | literally | 66 | literally |
| 67 | --fix EXPERIMENTAL - may create horrible results | ||
| 68 | If correctable single-line errors exist, create | ||
| 69 | "<inputfile>.EXPERIMENTAL-checkpatch-fixes" | ||
| 70 | with potential errors corrected to the preferred | ||
| 71 | checkpatch style | ||
| 66 | -h, --help, --version display this help and exit | 72 | -h, --help, --version display this help and exit |
| 67 | 73 | ||
| 68 | When FILE is - read standard input. | 74 | When FILE is - read standard input. |
| @@ -114,7 +120,7 @@ GetOptions( | |||
| 114 | 'summary!' => \$summary, | 120 | 'summary!' => \$summary, |
| 115 | 'mailback!' => \$mailback, | 121 | 'mailback!' => \$mailback, |
| 116 | 'summary-file!' => \$summary_file, | 122 | 'summary-file!' => \$summary_file, |
| 117 | 123 | 'fix!' => \$fix, | |
| 118 | 'debug=s' => \%debug, | 124 | 'debug=s' => \%debug, |
| 119 | 'test-only=s' => \$tst_only, | 125 | 'test-only=s' => \$tst_only, |
| 120 | 'h|help' => \$help, | 126 | 'h|help' => \$help, |
| @@ -367,6 +373,7 @@ $chk_signoff = 0 if ($file); | |||
| 367 | 373 | ||
| 368 | my @rawlines = (); | 374 | my @rawlines = (); |
| 369 | my @lines = (); | 375 | my @lines = (); |
| 376 | my @fixed = (); | ||
| 370 | my $vname; | 377 | my $vname; |
| 371 | for my $filename (@ARGV) { | 378 | for my $filename (@ARGV) { |
| 372 | my $FILE; | 379 | my $FILE; |
| @@ -394,6 +401,7 @@ for my $filename (@ARGV) { | |||
| 394 | } | 401 | } |
| 395 | @rawlines = (); | 402 | @rawlines = (); |
| 396 | @lines = (); | 403 | @lines = (); |
| 404 | @fixed = (); | ||
| 397 | } | 405 | } |
| 398 | 406 | ||
| 399 | exit($exit); | 407 | exit($exit); |
| @@ -434,7 +442,7 @@ sub parse_email { | |||
| 434 | $comment = $2 if defined $2; | 442 | $comment = $2 if defined $2; |
| 435 | $formatted_email =~ s/$address.*$//; | 443 | $formatted_email =~ s/$address.*$//; |
| 436 | $name = $formatted_email; | 444 | $name = $formatted_email; |
| 437 | $name =~ s/^\s+|\s+$//g; | 445 | $name = trim($name); |
| 438 | $name =~ s/^\"|\"$//g; | 446 | $name =~ s/^\"|\"$//g; |
| 439 | # If there's a name left after stripping spaces and | 447 | # If there's a name left after stripping spaces and |
| 440 | # leading quotes, and the address doesn't have both | 448 | # leading quotes, and the address doesn't have both |
| @@ -449,9 +457,9 @@ sub parse_email { | |||
| 449 | } | 457 | } |
| 450 | } | 458 | } |
| 451 | 459 | ||
| 452 | $name =~ s/^\s+|\s+$//g; | 460 | $name = trim($name); |
| 453 | $name =~ s/^\"|\"$//g; | 461 | $name =~ s/^\"|\"$//g; |
| 454 | $address =~ s/^\s+|\s+$//g; | 462 | $address = trim($address); |
| 455 | $address =~ s/^\<|\>$//g; | 463 | $address =~ s/^\<|\>$//g; |
| 456 | 464 | ||
| 457 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars | 465 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars |
| @@ -467,9 +475,9 @@ sub format_email { | |||
| 467 | 475 | ||
| 468 | my $formatted_email; | 476 | my $formatted_email; |
| 469 | 477 | ||
| 470 | $name =~ s/^\s+|\s+$//g; | 478 | $name = trim($name); |
| 471 | $name =~ s/^\"|\"$//g; | 479 | $name =~ s/^\"|\"$//g; |
| 472 | $address =~ s/^\s+|\s+$//g; | 480 | $address = trim($address); |
| 473 | 481 | ||
| 474 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars | 482 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars |
| 475 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes | 483 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes |
| @@ -1291,19 +1299,25 @@ sub ERROR { | |||
| 1291 | if (report("ERROR", $_[0], $_[1])) { | 1299 | if (report("ERROR", $_[0], $_[1])) { |
| 1292 | our $clean = 0; | 1300 | our $clean = 0; |
| 1293 | our $cnt_error++; | 1301 | our $cnt_error++; |
| 1302 | return 1; | ||
| 1294 | } | 1303 | } |
| 1304 | return 0; | ||
| 1295 | } | 1305 | } |
| 1296 | sub WARN { | 1306 | sub WARN { |
| 1297 | if (report("WARNING", $_[0], $_[1])) { | 1307 | if (report("WARNING", $_[0], $_[1])) { |
| 1298 | our $clean = 0; | 1308 | our $clean = 0; |
| 1299 | our $cnt_warn++; | 1309 | our $cnt_warn++; |
| 1310 | return 1; | ||
| 1300 | } | 1311 | } |
| 1312 | return 0; | ||
| 1301 | } | 1313 | } |
| 1302 | sub CHK { | 1314 | sub CHK { |
| 1303 | if ($check && report("CHECK", $_[0], $_[1])) { | 1315 | if ($check && report("CHECK", $_[0], $_[1])) { |
| 1304 | our $clean = 0; | 1316 | our $clean = 0; |
| 1305 | our $cnt_chk++; | 1317 | our $cnt_chk++; |
| 1318 | return 1; | ||
| 1306 | } | 1319 | } |
| 1320 | return 0; | ||
| 1307 | } | 1321 | } |
| 1308 | 1322 | ||
| 1309 | sub check_absolute_file { | 1323 | sub check_absolute_file { |
| @@ -1334,6 +1348,29 @@ sub check_absolute_file { | |||
| 1334 | } | 1348 | } |
| 1335 | } | 1349 | } |
| 1336 | 1350 | ||
| 1351 | sub trim { | ||
| 1352 | my ($string) = @_; | ||
| 1353 | |||
| 1354 | $string =~ s/(^\s+|\s+$)//g; | ||
| 1355 | |||
| 1356 | return $string; | ||
| 1357 | } | ||
| 1358 | |||
| 1359 | sub tabify { | ||
| 1360 | my ($leading) = @_; | ||
| 1361 | |||
| 1362 | my $source_indent = 8; | ||
| 1363 | my $max_spaces_before_tab = $source_indent - 1; | ||
| 1364 | my $spaces_to_tab = " " x $source_indent; | ||
| 1365 | |||
| 1366 | #convert leading spaces to tabs | ||
| 1367 | 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g; | ||
| 1368 | #Remove spaces before a tab | ||
| 1369 | 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g; | ||
| 1370 | |||
| 1371 | return "$leading"; | ||
| 1372 | } | ||
| 1373 | |||
| 1337 | sub pos_last_openparen { | 1374 | sub pos_last_openparen { |
| 1338 | my ($line) = @_; | 1375 | my ($line) = @_; |
| 1339 | 1376 | ||
| @@ -1425,6 +1462,8 @@ sub process { | |||
| 1425 | $linenr++; | 1462 | $linenr++; |
| 1426 | $line = $rawline; | 1463 | $line = $rawline; |
| 1427 | 1464 | ||
| 1465 | push(@fixed, $rawline) if ($fix); | ||
| 1466 | |||
| 1428 | if ($rawline=~/^\+\+\+\s+(\S+)/) { | 1467 | if ($rawline=~/^\+\+\+\s+(\S+)/) { |
| 1429 | $setup_docs = 0; | 1468 | $setup_docs = 0; |
| 1430 | if ($1 =~ m@Documentation/kernel-parameters.txt$@) { | 1469 | if ($1 =~ m@Documentation/kernel-parameters.txt$@) { |
| @@ -1616,16 +1655,29 @@ sub process { | |||
| 1616 | "Non-standard signature: $sign_off\n" . $herecurr); | 1655 | "Non-standard signature: $sign_off\n" . $herecurr); |
| 1617 | } | 1656 | } |
| 1618 | if (defined $space_before && $space_before ne "") { | 1657 | if (defined $space_before && $space_before ne "") { |
| 1619 | WARN("BAD_SIGN_OFF", | 1658 | if (WARN("BAD_SIGN_OFF", |
| 1620 | "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); | 1659 | "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) && |
| 1660 | $fix) { | ||
| 1661 | $fixed[$linenr - 1] = | ||
| 1662 | "$ucfirst_sign_off $email"; | ||
| 1663 | } | ||
| 1621 | } | 1664 | } |
| 1622 | if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { | 1665 | if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { |
| 1623 | WARN("BAD_SIGN_OFF", | 1666 | if (WARN("BAD_SIGN_OFF", |
| 1624 | "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr); | 1667 | |
