We should skip over and check the lines which follow preprocessor statements, labels, and blank lines. These all have legitimate reasons to be indented differently.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -1434,7 +1434,7 @@ sub process { · 1433 unmodified lines | ||
| 1434 | 1434 | if ($s =~ s/^\s*\\//) { |
| 1435 | 1435 | $continuation = 1; |
| 1436 | 1436 | } |
| 1437 | − if ($s =~ s/^\s*\n//) { | |
| 1437 | + if ($s =~ s/^\s*?\n//) { | |
| 1438 | 1438 | $check = 1; |
| 1439 | 1439 | $cond_lines++; |
| 1440 | 1440 | } |
| @@ -1446,15 +1446,20 @@ sub process { · 5 unmodified lines | ||
| 1446 | 1446 | $check = 0; |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | − # Ignore the current line if its is a preprocessor | |
| 1450 | − # line. | |
| 1451 | − if ($s =~ /^\s*#\s*/) { | |
| 1452 | − $check = 0; | |
| 1453 | − } | |
| 1449 | + my $cond_ptr = -1; | |
| 1450 | + while ($cond_ptr != $cond_lines) { | |
| 1451 | + $cond_ptr = $cond_lines; | |
| 1454 | 1452 | |
| 1455 | − # Ignore the current line if it is label. | |
| 1456 | − if ($s =~ /^\s*$Ident\s*:/) { | |
| 1457 | − $check = 0; | |
| 1453 | + # Ignore: | |
| 1454 | + # 1) blank lines, they should be at 0, | |
| 1455 | + # 2) preprocessor lines, and | |
| 1456 | + # 3) labels. | |
| 1457 | + if ($s =~ /^\s*?\n/ || | |
| 1458 | + $s =~ /^\s*#\s*?/ || | |
| 1459 | + $s =~ /^\s*$Ident\s*:/) { | |
| 1460 | + $s =~ s/^.*?\n//; | |
| 1461 | + $cond_lines++; | |
| 1462 | + } | |
| 1458 | 1463 | } |
| 1459 | 1464 | |
| 1460 | 1465 | my (undef, $sindent) = line_stats("+" . $s); |
| @@ -1470,7 +1475,7 @@ sub process { · 9 unmodified lines | ||
| 1470 | 1475 | $stat_real = "[...]\n$stat_real"; |
| 1471 | 1476 | } |
| 1472 | 1477 | |
| 1473 | − ##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"; | |
| 1478 | + #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"; | |
| 1474 | 1479 | |
| 1475 | 1480 | if ($check && (($sindent % 8) != 0 || |
| 1476 | 1481 | ($sindent <= $indent && $s ne ''))) { |