Commit 9f5af480 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: improve SUSPECT_CODE_INDENT test

Many lines exist like

	if (foo)
			bar;

where the tabbed indentation of the branch is not one more than the "if"
line above it.

checkpatch should emit a warning on those lines.

Miscellenea:

o Remove comments from branch blocks
o Skip blank lines in block
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 9d3e3c70
...@@ -3076,15 +3076,22 @@ sub process { ...@@ -3076,15 +3076,22 @@ sub process {
substr($s, 0, length($c), ''); substr($s, 0, length($c), '');
# Make sure we remove the line prefixes as we have # remove inline comments
# none on the first line, and are going to readd them $s =~ s/$;/ /g;
# where necessary. $c =~ s/$;/ /g;
$s =~ s/\n./\n/gs;
# Find out how long the conditional actually is. # Find out how long the conditional actually is.
my @newlines = ($c =~ /\n/gs); my @newlines = ($c =~ /\n/gs);
my $cond_lines = 1 + $#newlines; my $cond_lines = 1 + $#newlines;
# Make sure we remove the line prefixes as we have
# none on the first line, and are going to readd them
# where necessary.
$s =~ s/\n./\n/gs;
while ($s =~ /\n\s+\\\n/) {
$cond_lines += $s =~ s/\n\s+\\\n/\n/g;
}
# We want to check the first line inside the block # We want to check the first line inside the block
# starting at the end of the conditional, so remove: # starting at the end of the conditional, so remove:
# 1) any blank line termination # 1) any blank line termination
...@@ -3150,8 +3157,10 @@ sub process { ...@@ -3150,8 +3157,10 @@ sub process {
#print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n"; #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
if ($check && (($sindent % 8) != 0 || if ($check && $s ne '' &&
($sindent <= $indent && $s ne ''))) { (($sindent % 8) != 0 ||
($sindent < $indent) ||
($sindent > $indent + 8))) {
WARN("SUSPECT_CODE_INDENT", WARN("SUSPECT_CODE_INDENT",
"suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
} }
......
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