checkpatch: Make "return is not a function" test quieter
A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.10.1402261908070.2159@hadrien
A message that is not in the archive (sent off-list or not yet received): 20140226182832.GA23053@cloud
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20140227170811.GA28796@thin
A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.10.1402271811010.4439@hadrien
A message that is not in the archive (sent off-list or not yet received): 20140227172017.GA29133@thin
A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.10.1402271822540.4439@hadrien
A message that is not in the archive (sent off-list or not yet received): 1393523563.24588.101.camel@joe-AO722
A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.10.1402271856530.4439@hadrien
A message that is not in the archive (sent off-list or not yet received): 1393524256.24588.103.camel@joe-AO722
A message that is not in the archive (sent off-list or not yet received): [email protected]
Joe Perches
maintainerPATCH 1/1 checkpatch: Make "return is not a function" test quieter
This test is a bit noisy and opinions seem to agree that it should not warn in a lot more situations.
It seems people agree that:
return (foo || bar); and return foo || bar;
are both acceptable style and checkpatch should be silent about them.
For now, it warns on parentheses around a simple constant or a single function or a ternary.
return (foo); return (foo(bar)); return (foo ? bar : baz);
The last ternary test may be quieted in the future.
Modify the deparenthesize function to only strip balanced leading and trailing parentheses.
--- scripts/checkpatch.pl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
scripts/checkpatch.pl +15 -7
@@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; sub deparenthesize { my ($string) = @_; return "" if (!defined($string)); - $string =~ s@^\s*\(\s*@@g; - $string =~ s@\s*\)\s*$@@g; + + while ($string =~ /^\s*\(.*\)\s*$/) { + $string =~ s@^\s*\(\s*@@; + $string =~ s@\s*\)\s*$@@; + } + $string =~ s@\s+@ @g; + return $string; }
@@ -3362,14 +3367,17 @@ sub process { } } -# Return is not a function. +# return is not a function if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { my $spacing = $1; if ($^V && $^V ge 5.10.0 && - $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { - ERROR("RETURN_PARENTHESES", - "return is not a function, parentheses are not required\n" . $herecurr); - + $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { + my $value = $1; + $value = deparenthesize($value); + if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) { + ERROR("RETURN_PARENTHESES", + "return is not a function, parentheses are not required\n" . $herecurr); + } } elsif ($spacing !~ /\s+/) { ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr);
Quoted 19 lines · Joe Perches
This test is a bit noisy and opinions seem to agree that it should not warn in a lot more situations.
It seems people agree that:
return (foo || bar); and return foo || bar;are both acceptable style and checkpatch should be silent about them.
For now, it warns on parentheses around a simple constant or a single function or a ternary.
return (foo); return (foo(bar)); return (foo ? bar : baz);
Quoted 6 lines
The last ternary test may be quieted in the future.
Modify the deparenthesize function to only strip balanced leading and trailing parentheses.
Signed-off-by Joe Perches <[email protected]>
I'd suggest dropping the warning for parenthesized ternaries as well, but in any case:
Quoted 53 lines
scripts/checkpatch.pl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)scripts/checkpatch.pl +15
-7@@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; sub deparenthesize { my ($string) = @_; return "" if (!defined($string)); - $string =~ s@^\s*\(\s*@@g; - $string =~ s@\s*\)\s*$@@g; + + while ($string =~ /^\s*\(.*\)\s*$/) { + $string =~ s@^\s*\(\s*@@; + $string =~ s@\s*\)\s*$@@; + } + $string =~ s@\s+@ @g; + return $string; }@@ -3362,14 +3367,17 @@ sub process { } } -# Return is not a function. +# return is not a function if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { my $spacing = $1; if ($^V && $^V ge 5.10.0 && - $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { - ERROR("RETURN_PARENTHESES", - "return is not a function, parentheses are not required\n" . $herecurr); - + $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { + my $value = $1; + $value = deparenthesize($value); + if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) { + ERROR("RETURN_PARENTHESES", + "return is not a function, parentheses are not required\n" . $herecurr); + } } elsif ($spacing !~ /\s+/) { ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr);Signature · 4 lines
-- You received this message because you are subscribed to the Google Groups "opw-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.