mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-17 02:15:57 +00:00
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>
This commit is contained in:
parent
85ad978c62
commit
5b9553abfc
@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
|
|||||||
sub deparenthesize {
|
sub deparenthesize {
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
return "" if (!defined($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;
|
$string =~ s@\s+@ @g;
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3374,14 +3379,17 @@ sub process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return is not a function.
|
# return is not a function
|
||||||
if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
|
if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
|
||||||
my $spacing = $1;
|
my $spacing = $1;
|
||||||
if ($^V && $^V ge 5.10.0 &&
|
if ($^V && $^V ge 5.10.0 &&
|
||||||
$stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
|
$stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
|
||||||
ERROR("RETURN_PARENTHESES",
|
my $value = $1;
|
||||||
"return is not a function, parentheses are not required\n" . $herecurr);
|
$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+/) {
|
} elsif ($spacing !~ /\s+/) {
|
||||||
ERROR("SPACING",
|
ERROR("SPACING",
|
||||||
"space required before the open parenthesis '('\n" . $herecurr);
|
"space required before the open parenthesis '('\n" . $herecurr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user