Commit 8d182478 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: add --fix option for a couple OPEN_BRACE misuses

Style misuses of these types are corrected:

  typedef struct foo
  {
        int bar;
  };

  int foo(int bar) { return bar+1;
  }

  int foo(int bar) {
        return bar+1;
  }
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bd474ca0
...@@ -3164,17 +3164,40 @@ sub process { ...@@ -3164,17 +3164,40 @@ sub process {
# function brace can't be on same line, except for #defines of do while, # function brace can't be on same line, except for #defines of do while,
# or if closed on same line # or if closed on same line
if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and
!($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
ERROR("OPEN_BRACE", if (ERROR("OPEN_BRACE",
"open brace '{' following function declarations go on the next line\n" . $herecurr); "open brace '{' following function declarations go on the next line\n" . $herecurr) &&
$fix) {
fix_delete_line($fixlinenr, $rawline);
my $fixed_line = $rawline;
$fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*){(.*)$/;
my $line1 = $1;
my $line2 = $2;
fix_insert_line($fixlinenr, ltrim($line1));
fix_insert_line($fixlinenr, "\+{");
if ($line2 !~ /^\s*$/) {
fix_insert_line($fixlinenr, "\+\t" . trim($line2));
}
}
} }
# open braces for enum, union and struct go on the same line. # open braces for enum, union and struct go on the same line.
if ($line =~ /^.\s*{/ && if ($line =~ /^.\s*{/ &&
$prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
ERROR("OPEN_BRACE", if (ERROR("OPEN_BRACE",
"open brace '{' following $1 go on the same line\n" . $hereprev); "open brace '{' following $1 go on the same line\n" . $hereprev) &&
$fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
fix_delete_line($fixlinenr - 1, $prevrawline);
fix_delete_line($fixlinenr, $rawline);
my $fixedline = rtrim($prevrawline) . " {";
fix_insert_line($fixlinenr, $fixedline);
$fixedline = $rawline;
$fixedline =~ s/^(.\s*){\s*/$1\t/;
if ($fixedline !~ /^\+\s*$/) {
fix_insert_line($fixlinenr, $fixedline);
}
}
} }
# missing space after union, struct or enum definition # missing space after union, struct or enum definition
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment