History

checkpatch: add fix_insert_line and fix_delete_line helpers

Neaten the uses of patch/file line insertions or deletions. Hide the mechanism used.

Joe Perches committed 12 years ago

Commit f2d7e4d1 parent d752fcc1 file · +29 −36Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+29−36
@@ -1593,6 +1593,27 @@ sub fix_inserted_deleted_lines { · 1592 unmodified lines
1593 return @lines;1593 return @lines;
1594}1594}
1595 1595
1596sub 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
1606sub 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
1596sub ERROR {1617sub ERROR {
1597 my ($type, $msg) = @_;1618 my ($type, $msg) = @_;
1598 1619
@@ -2447,11 +2468,7 @@ sub process { · 848 unmodified lines
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 { · 4 unmodified lines
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 { · 36 unmodified lines
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 { · 348 unmodified lines
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