diff options
author | Joe Perches <joe@perches.com> | 2014-04-03 17:49:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-03 19:21:14 -0400 |
commit | 5b9553abfc97f923b99868a04c3b3d99a6014163 (patch) | |
tree | 3d54a69799ee4e749d001d33834907b9e76460ae /scripts | |
parent | 85ad978c626a425c0bacd137bf15403e867c9134 (diff) |
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.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Cc: Monam Agarwal <monamagarwal123@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c624b04d0070..f0ea8a037a6d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; | |||
439 | sub deparenthesize { | 439 | sub deparenthesize { |
440 | my ($string) = @_; | 440 | my ($string) = @_; |
441 | return "" if (!defined($string)); | 441 | return "" if (!defined($string)); |
442 | $string =~ s@^\s*\(\s*@@g; | 442 | |
443 | $string =~ s@\s*\)\s*$@@g; | 443 | while ($string =~ /^\s*\(.*\)\s*$/) { |
444 | $string =~ s@^\s*\(\s*@@; | ||
445 | $string =~ s@\s*\)\s*$@@; | ||
446 | } | ||
447 | |||
444 | $string =~ s@\s+@ @g; | 448 | $string =~ s@\s+@ @g; |
449 | |||
445 | return $string; | 450 | return $string; |
446 | } | 451 | } |
447 | 452 | ||
@@ -3374,14 +3379,17 @@ sub process { | |||
3374 | } | 3379 | } |
3375 | } | 3380 | } |
3376 | 3381 | ||
3377 | # Return is not a function. | 3382 | # return is not a function |
3378 | if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { | 3383 | if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { |
3379 | my $spacing = $1; | 3384 | my $spacing = $1; |
3380 | if ($^V && $^V ge 5.10.0 && | 3385 | if ($^V && $^V ge 5.10.0 && |
3381 | $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { | 3386 | $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { |
3382 | ERROR("RETURN_PARENTHESES", | 3387 | my $value = $1; |
3383 | "return is not a function, parentheses are not required\n" . $herecurr); | 3388 | $value = deparenthesize($value); |
3384 | 3389 | if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) { | |
3390 | ERROR("RETURN_PARENTHESES", | ||
3391 | "return is not a function, parentheses are not required\n" . $herecurr); | ||
3392 | } | ||
3385 | } elsif ($spacing !~ /\s+/) { | 3393 | } elsif ($spacing !~ /\s+/) { |
3386 | ERROR("SPACING", | 3394 | ERROR("SPACING", |
3387 | "space required before the open parenthesis '('\n" . $herecurr); | 3395 | "space required before the open parenthesis '('\n" . $herecurr); |