Check on the spacing before square brackets. We should only allow spaces there if this is part of a type definition or an initialialiser.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -1435,6 +1435,17 @@ sub process { · 1434 unmodified lines | ||
| 1435 | 1435 | ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | +# check for spacing round square brackets; allowed: | |
| 1439 | +# 1. with a type on the left -- int [] a; | |
| 1440 | +# 2. at the beginning of a line for slice initialisers -- [0..10] = 5, | |
| 1441 | + while ($line =~ /(.*?\s)\[/g) { | |
| 1442 | + my ($where, $prefix) = ($-[1], $1); | |
| 1443 | + if ($prefix !~ /$Type\s+$/ && | |
| 1444 | + ($where != 0 || $prefix !~ /^.\s+$/)) { | |
| 1445 | + ERROR("space prohibited before open square bracket '['\n" . $herecurr); | |
| 1446 | + } | |
| 1447 | + } | |
| 1448 | + | |
| 1438 | 1449 | # check for spaces between functions and their parentheses. |
| 1439 | 1450 | while ($line =~ /($Ident)\s+\(/g) { |
| 1440 | 1451 | my $name = $1; |