Skip to content

Commit

Permalink
checkpatch: toughen trailing if statement checks and extend them to w…
Browse files Browse the repository at this point in the history
…hile and for

Extend the trailing statement checks to report a trailing semi-colon ';'
as we really want it on the next line and indented so it is really really
obvious.  Also extend the tests to include while and for.

Signed-off-by: Andy Whitcroft <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
awhitcroft authored and torvalds committed Jul 24, 2008
1 parent 8d31cfc commit 5321016
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,8 @@ sub process {
$ctx_ln++;
}

##print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
##print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";

if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
ERROR("that open brace { should be on the previous line\n" .
Expand Down Expand Up @@ -1713,7 +1713,7 @@ sub process {
}

# Check for illegal assignment in if conditional.
if ($line =~ /\bif\s*\(/) {
if ($line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
my ($s, $c) = ($stat, $cond);

if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {
Expand All @@ -1725,8 +1725,8 @@ sub process {
substr($s, 0, length($c), '');
$s =~ s/\n.*//g;
$s =~ s/$;//g; # Remove any comments
if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/ &&
$c !~ /^.\s*\#\s*if/)
if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
$c !~ /}\s*while\s*/)
{
ERROR("trailing statements should be on next line\n" . $herecurr);
}
Expand Down

0 comments on commit 5321016

Please sign in to comment.