Messages in this thread Patch in this message | | | From | Joe Perches <> | Subject | [PATCH] checkpatch: Avoid multiple line dereferences | Date | Wed, 2 Nov 2016 14:25:13 -0700 |
| |
Code that puts a single dereferencing identifier on multiple lines like:
struct_identifier->member[index]. member = <foo>;
is generally hard to follow.
Prefer that dereferencing identifiers be single line.
Signed-off-by: Joe Perches <joe@perches.com> --- scripts/checkpatch.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index fdacd759078e..22abb4af5b4f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3440,6 +3440,18 @@ sub process { #ignore lines not being added next if ($line =~ /^[^\+]/); +# check for dereferences that span multiple lines + if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ && + $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) { + $prevline =~ /($Lval\s*(?:\.|->))\s*$/; + my $ref = $1; + $line =~ /^.\s*($Lval)/; + $ref .= $1; + $ref =~ s/\s//g; + WARN("MULTILINE_DEREFERENCE", + "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev); + } + # check for declarations of signed or unsigned without int while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) { my $type = $1; -- 2.10.0.rc2.1.g053435c
| |