Skip to content

Commit

Permalink
checkpatch: trivial fix for trailing statements check
Browse files Browse the repository at this point in the history
In case if the statement and the conditional are in one line, the line
appears in the report doubly.

And items of this check have no blank line before the next item.

This patch fixes these trivial problems, to improve readability of the
report.

[sample.c]
  > if (cond1
  >        && cond2
  >        && cond3) func_foo();
  >
  > if (cond4) func_bar();

Before:
  > ERROR: trailing statements should be on next line
  > #1: FILE: sample.c:1:
  > +if (cond1
  > [...]
  > +       && cond3) func_foo();
  > ERROR: trailing statements should be on next line
  > analogdevicesinc#5: FILE: sample.c:5:
  > +if (cond4) func_bar();
  > +if (cond4) func_bar();
  > total: 2 errors, 0 warnings, 5 lines checked

After:
  > ERROR: trailing statements should be on next line
  > #1: FILE: sample.c:1:
  > +if (cond1
  > [...]
  > +       && cond3) func_foo();
  >
  > ERROR: trailing statements should be on next line
  > analogdevicesinc#5: FILE: sample.c:5:
  > +if (cond4) func_bar();
  >
  > total: 2 errors, 0 warnings, 5 lines checked

Signed-off-by: Hidetoshi Seto <[email protected]>
Cc: Andy Whitcroft <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Hidetoshi Seto authored and torvalds committed Mar 6, 2010
1 parent 8f53a9b commit 42bdf74
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2182,8 +2182,10 @@ sub process {
# Find out how long the conditional actually is.
my @newlines = ($c =~ /\n/gs);
my $cond_lines = 1 + $#newlines;
my $stat_real = '';

my $stat_real = raw_line($linenr, $cond_lines);
$stat_real = raw_line($linenr, $cond_lines)
. "\n" if ($cond_lines);
if (defined($stat_real) && $cond_lines > 1) {
$stat_real = "[...]\n$stat_real";
}
Expand Down

0 comments on commit 42bdf74

Please sign in to comment.