Skip to content

Commit

Permalink
checkpatch: add fix_insert_line and fix_delete_line helpers
Browse files Browse the repository at this point in the history
Neaten the uses of patch/file line insertions or deletions.  Hide the
mechanism used.

Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Aug 7, 2014
1 parent d752fcc commit f2d7e4d
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,27 @@ sub fix_inserted_deleted_lines {
return @lines;
}

sub fix_insert_line {
my ($linenr, $line) = @_;

my $inserted = {
LINENR => $linenr,
LINE => $line,
};
push(@fixed_inserted, $inserted);
}

sub fix_delete_line {
my ($linenr, $line) = @_;

my $deleted = {
LINENR => $linenr,
LINE => $line,
};

push(@fixed_deleted, $deleted);
}

sub ERROR {
my ($type, $msg) = @_;

Expand Down Expand Up @@ -2447,11 +2468,7 @@ sub process {
if (CHK("LINE_SPACING",
"Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
$fix) {
my $inserted = {
LINENR => $fixlinenr,
LINE => "\+",
};
push(@fixed_inserted, $inserted);
fix_insert_line($fixlinenr, "\+");
}
}

Expand All @@ -2462,11 +2479,7 @@ sub process {
if (CHK("LINE_SPACING",
"Please don't use multiple blank lines\n" . $hereprev) &&
$fix) {
my $deleted = {
LINENR => $fixlinenr,
LINE => $rawline,
};
push(@fixed_deleted, $deleted);
fix_delete_line($fixlinenr, $rawline);
}

$last_blank_line = $linenr;
Expand Down Expand Up @@ -2509,11 +2522,7 @@ sub process {
if (WARN("LINE_SPACING",
"Missing a blank line after declarations\n" . $hereprev) &&
$fix) {
my $inserted = {
LINENR => $fixlinenr,
LINE => "\+",
};
push(@fixed_inserted, $inserted);
fix_insert_line($fixlinenr, "\+");
}
}

Expand Down Expand Up @@ -2868,31 +2877,15 @@ sub process {
$prevline =~ /(?:^|[^=])=\s*$/) {
if (ERROR("OPEN_BRACE",
"that open brace { should be on the previous line\n" . $hereprev) &&
$fix && $prevline =~ /^\+/) {
my $deleted = {
LINENR => $fixlinenr - 1,
LINE => $prevrawline,
};
push(@fixed_deleted, $deleted);
$deleted = {
LINENR => $fixlinenr,
LINE => $rawline,
};
push(@fixed_deleted, $deleted);
$fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
fix_delete_line($fixlinenr - 1, $prevrawline);
fix_delete_line($fixlinenr, $rawline);
my $fixedline = $prevrawline;
$fixedline =~ s/\s*=\s*$/ = {/;
my $inserted = {
LINENR => $fixlinenr,
LINE => $fixedline,
};
push(@fixed_inserted, $inserted);
fix_insert_line($fixlinenr, $fixedline);
$fixedline = $line;
$fixedline =~ s/^(.\s*){\s*/$1/;
$inserted = {
LINENR => $fixlinenr,
LINE => $fixedline,
};
push(@fixed_inserted, $inserted);
fix_insert_line($fixlinenr, $fixedline);
}
}

Expand Down

0 comments on commit f2d7e4d

Please sign in to comment.