Skip to content

Commit 91cb519

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: expand parenthesis alignment test to declarations, functions and assignments
Currently the parenthesis alignment test works only on misalignments of if statements like if (foo(bar, baz) Expand the test to find misalignments like: static inline int foo(int bar, int baz) and foo(bar, baz); and foo = bar(baz, qux); Expand the $Inline keyword for __inline and __inline__ too. Add $Inline to $Declare so it also matches "static inline <foo>". These checks are only performed with --strict. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7ebd05e commit 91cb519

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ sub hash_show_words {
281281
__weak
282282
}x;
283283
our $Modifier;
284-
our $Inline = qr{inline|__always_inline|noinline};
284+
our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__};
285285
our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
286286
our $Lval = qr{$Ident(?:$Member)*};
287287

@@ -304,6 +304,8 @@ sub hash_show_words {
304304
&&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
305305
}x;
306306

307+
our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
308+
307309
our $NonptrType;
308310
our $NonptrTypeWithAttr;
309311
our $Type;
@@ -429,7 +431,7 @@ sub build_types {
429431
(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)?
430432
(?:\s+$Inline|\s+$Modifier)*
431433
}x;
432-
$Declare = qr{(?:$Storage\s+)?$Type};
434+
$Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
433435
}
434436
build_types();
435437

@@ -1607,7 +1609,7 @@ sub pos_last_openparen {
16071609
}
16081610
}
16091611

1610-
return $last_openparen + 1;
1612+
return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
16111613
}
16121614

16131615
sub process {
@@ -2200,7 +2202,7 @@ sub process {
22002202

22012203
# check multi-line statement indentation matches previous line
22022204
if ($^V && $^V ge 5.10.0 &&
2203-
$prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/) {
2205+
$prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|$Ident\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
22042206
$prevline =~ /^\+(\t*)(.*)$/;
22052207
my $oldindent = $1;
22062208
my $rest = $2;

0 commit comments

Comments
 (0)