diff options
author | Joe Perches <joe@perches.com> | 2014-08-06 19:11:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 21:01:28 -0400 |
commit | f2d7e4d4398092d14fb039cb4d38e502d3f019ee (patch) | |
tree | 18b238e5a05361610b5c8e90c40504fb5c204c14 /scripts/checkpatch.pl | |
parent | d752fcc88b7dddc0bbe6d43b658b306a9d7d1dae (diff) |
checkpatch: add fix_insert_line and fix_delete_line helpers
Neaten the uses of patch/file line insertions or deletions. Hide the
mechanism used.
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/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f3d9a883f8be..7c290693b8af 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -1593,6 +1593,27 @@ sub fix_inserted_deleted_lines { | |||
1593 | return @lines; | 1593 | return @lines; |
1594 | } | 1594 | } |
1595 | 1595 | ||
1596 | sub fix_insert_line { | ||
1597 | my ($linenr, $line) = @_; | ||
1598 | |||
1599 | my $inserted = { | ||
1600 | LINENR => $linenr, | ||
1601 | LINE => $line, | ||
1602 | }; | ||
1603 | push(@fixed_inserted, $inserted); | ||
1604 | } | ||
1605 | |||
1606 | sub fix_delete_line { | ||
1607 | my ($linenr, $line) = @_; | ||
1608 | |||
1609 | my $deleted = { | ||
1610 | LINENR => $linenr, | ||
1611 | LINE => $line, | ||
1612 | }; | ||
1613 | |||
1614 | push(@fixed_deleted, $deleted); | ||
1615 | } | ||
1616 | |||
1596 | sub ERROR { | 1617 | sub ERROR { |
1597 | my ($type, $msg) = @_; | 1618 | my ($type, $msg) = @_; |
1598 | 1619 | ||
@@ -2447,11 +2468,7 @@ sub process { | |||
2447 | if (CHK("LINE_SPACING", | 2468 | if (CHK("LINE_SPACING", |
2448 | "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) && | 2469 | "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) && |
2449 | $fix) { | 2470 | $fix) { |
2450 | my $inserted = { | 2471 | fix_insert_line($fixlinenr, "\+"); |
2451 | LINENR => $fixlinenr, | ||
2452 | LINE => "\+", | ||
2453 | }; | ||
2454 | push(@fixed_inserted, $inserted); | ||
2455 | } | 2472 | } |
2456 | } | 2473 | } |
2457 | 2474 | ||
@@ -2462,11 +2479,7 @@ sub process { | |||
2462 | if (CHK("LINE_SPACING", | 2479 | if (CHK("LINE_SPACING", |
2463 | "Please don't use multiple blank lines\n" . $hereprev) && | 2480 | "Please don't use multiple blank lines\n" . $hereprev) && |
2464 | $fix) { | 2481 | $fix) { |
2465 | my $deleted = { | 2482 | fix_delete_line($fixlinenr, $rawline); |
2466 | LINENR => $fixlinenr, | ||
2467 | LINE => $rawline, | ||
2468 | }; | ||
2469 | push(@fixed_deleted, $deleted); | ||
2470 | } | 2483 | } |
2471 | 2484 | ||
2472 | $last_blank_line = $linenr; | 2485 | $last_blank_line = $linenr; |
@@ -2509,11 +2522,7 @@ sub process { | |||
2509 | if (WARN("LINE_SPACING", | 2522 | if (WARN("LINE_SPACING", |
2510 | "Missing a blank line after declarations\n" . $hereprev) && | 2523 | "Missing a blank line after declarations\n" . $hereprev) && |
2511 | $fix) { | 2524 | $fix) { |
2512 | my $inserted = { | 2525 | fix_insert_line($fixlinenr, "\+"); |
2513 | LINENR => $fixlinenr, | ||
2514 | LINE => "\+", | ||
2515 | }; | ||
2516 | push(@fixed_inserted, $inserted); | ||
2517 | } | 2526 | } |
2518 | } | 2527 | } |
2519 | 2528 | ||
@@ -2868,31 +2877,15 @@ sub process { | |||
2868 | $prevline =~ /(?:^|[^=])=\s*$/) { | 2877 | $prevline =~ /(?:^|[^=])=\s*$/) { |
2869 | if (ERROR("OPEN_BRACE", | 2878 | if (ERROR("OPEN_BRACE", |
2870 | "that open brace { should be on the previous line\n" . $hereprev) && | 2879 | "that open brace { should be on the previous line\n" . $hereprev) && |
2871 | $fix && $prevline =~ /^\+/) { | 2880 | $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { |
2872 | my $deleted = { | 2881 | fix_delete_line($fixlinenr - 1, $prevrawline); |
2873 | LINENR => $fixlinenr - 1, | 2882 | fix_delete_line($fixlinenr, $rawline); |
2874 | LINE => $prevrawline, | ||
2875 | }; | ||
2876 | push(@fixed_deleted, $deleted); | ||
2877 | $deleted = { | ||
2878 | LINENR => $fixlinenr, | ||
2879 | LINE => $rawline, | ||
2880 | }; | ||
2881 | push(@fixed_deleted, $deleted); | ||
2882 | my $fixedline = $prevrawline; | 2883 | my $fixedline = $prevrawline; |
2883 | $fixedline =~ s/\s*=\s*$/ = {/; | 2884 | $fixedline =~ s/\s*=\s*$/ = {/; |
2884 | my $inserted = { | 2885 | fix_insert_line($fixlinenr, $fixedline); |
2885 | LINENR => $fixlinenr, | ||
2886 | LINE => $fixedline, | ||
2887 | }; | ||
2888 | push(@fixed_inserted, $inserted); | ||
2889 | $fixedline = $line; | 2886 | $fixedline = $line; |
2890 | $fixedline =~ s/^(.\s*){\s*/$1/; | 2887 | $fixedline =~ s/^(.\s*){\s*/$1/; |
2891 | $inserted = { | 2888 | fix_insert_line($fixlinenr, $fixedline); |
2892 | LINENR => $fixlinenr, | ||
2893 | LINE => $fixedline, | ||
2894 | }; | ||
2895 | push(@fixed_inserted, $inserted); | ||
2896 | } | 2889 | } |
2897 | } | 2890 | } |
2898 | 2891 | ||