checkpatch: toughen trailing if statement checks and extend them to while 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 <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
8d31cfcecf
commit
53210168fe
|
@ -1269,8 +1269,8 @@ sub process {
|
||||||
$ctx_ln++;
|
$ctx_ln++;
|
||||||
}
|
}
|
||||||
|
|
||||||
##print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
|
#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
|
||||||
##print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\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*{/) {
|
if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
|
||||||
ERROR("that open brace { should be on the previous line\n" .
|
ERROR("that open brace { should be on the previous line\n" .
|
||||||
|
@ -1713,7 +1713,7 @@ sub process {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for illegal assignment in if conditional.
|
# 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);
|
my ($s, $c) = ($stat, $cond);
|
||||||
|
|
||||||
if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {
|
if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {
|
||||||
|
@ -1725,8 +1725,8 @@ sub process {
|
||||||
substr($s, 0, length($c), '');
|
substr($s, 0, length($c), '');
|
||||||
$s =~ s/\n.*//g;
|
$s =~ s/\n.*//g;
|
||||||
$s =~ s/$;//g; # Remove any comments
|
$s =~ s/$;//g; # Remove any comments
|
||||||
if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/ &&
|
if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
|
||||||
$c !~ /^.\s*\#\s*if/)
|
$c !~ /}\s*while\s*/)
|
||||||
{
|
{
|
||||||
ERROR("trailing statements should be on next line\n" . $herecurr);
|
ERROR("trailing statements should be on next line\n" . $herecurr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue