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
15931593 return @lines;
15941594 }
15951595
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+
15961617 sub ERROR {
15971618 my ($type, $msg) = @_;
15981619
@@ -2447,11 +2468,7 @@ sub process { · 848 unmodified lines
24472468 if (CHK("LINE_SPACING",
24482469 "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
24492470 $fix) {
2450− my $inserted = {
2451− LINENR => $fixlinenr,
2452− LINE => "\+",
2453− };
2454− push(@fixed_inserted, $inserted);
2471+ fix_insert_line($fixlinenr, "\+");
24552472 }
24562473 }
24572474
@@ -2462,11 +2479,7 @@ sub process { · 4 unmodified lines
24622479 if (CHK("LINE_SPACING",
24632480 "Please don't use multiple blank lines\n" . $hereprev) &&
24642481 $fix) {
2465− my $deleted = {
2466− LINENR => $fixlinenr,
2467− LINE => $rawline,
2468− };
2469− push(@fixed_deleted, $deleted);
2482+ fix_delete_line($fixlinenr, $rawline);
24702483 }
24712484
24722485 $last_blank_line = $linenr;
@@ -2509,11 +2522,7 @@ sub process { · 36 unmodified lines
25092522 if (WARN("LINE_SPACING",
25102523 "Missing a blank line after declarations\n" . $hereprev) &&
25112524 $fix) {
2512− my $inserted = {
2513− LINENR => $fixlinenr,
2514− LINE => "\+",
2515− };
2516− push(@fixed_inserted, $inserted);
2525+ fix_insert_line($fixlinenr, "\+");
25172526 }
25182527 }
25192528
@@ -2868,31 +2877,15 @@ sub process { · 348 unmodified lines
28682877 $prevline =~ /(?:^|[^=])=\s*$/) {
28692878 if (ERROR("OPEN_BRACE",
28702879 "that open brace { should be on the previous line\n" . $hereprev) &&
2871− $fix && $prevline =~ /^\+/) {
2872− my $deleted = {
2873− LINENR => $fixlinenr - 1,
2874− LINE => $prevrawline,
2875− };
2876− push(@fixed_deleted, $deleted);
2877− $deleted = {
2878− LINENR => $fixlinenr,
2879− LINE => $rawline,
2880− };
2881− push(@fixed_deleted, $deleted);
2880+ $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
2881+ fix_delete_line($fixlinenr - 1, $prevrawline);
2882+ fix_delete_line($fixlinenr, $rawline);
28822883 my $fixedline = $prevrawline;
28832884 $fixedline =~ s/\s*=\s*$/ = {/;
2884− my $inserted = {
2885− LINENR => $fixlinenr,
2886− LINE => $fixedline,
2887− };
2888− push(@fixed_inserted, $inserted);
2885+ fix_insert_line($fixlinenr, $fixedline);
28892886 $fixedline = $line;
28902887 $fixedline =~ s/^(.\s*){\s*/$1/;
2891− $inserted = {
2892− LINENR => $fixlinenr,
2893− LINE => $fixedline,
2894− };
2895− push(@fixed_inserted, $inserted);
2888+ fix_insert_line($fixlinenr, $fixedline);
28962889 }
28972890 }
28982891