History

checkpatch: check spacing for square brackets

Check on the spacing before square brackets. We should only allow spaces there if this is part of a type definition or an initialialiser.

Andy Whitcroft committed 18 years ago

Commit 8d31cfc1 parent e2a763c1 file · +11 −0Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+11−0
@@ -1435,6 +1435,17 @@ sub process { · 1434 unmodified lines
14351435 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
14361436 }
14371437
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+
14381449 # check for spaces between functions and their parentheses.
14391450 while ($line =~ /($Ident)\s+\(/g) {
14401451 my $name = $1;