public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: josh@joshtriplett.org
To: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Julia Lawall <julia.lawall@lip6.fr>,
	Monam Agarwal <monamagarwal123@gmail.com>,
	opw-kernel@googlegroups.com, Greg KH <gregkh@linuxfoundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [OPW kernel] [PATCH] checkpatch: Make "return is not a function" test quieter
Date: Thu, 27 Feb 2014 14:44:01 -0800	[thread overview]
Message-ID: <20140227224401.GA30335@cloud> (raw)
In-Reply-To: <1393529230.24588.114.camel@joe-AO722>

On Thu, Feb 27, 2014 at 11:27:10AM -0800, Joe Perches wrote:
> 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>

I'd suggest dropping the warning for parenthesized ternaries as well,
but in any case:

Reviewed-by: Josh Triplett <josh@joshtriplett.org>

>  scripts/checkpatch.pl | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 91308be..be4be81 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -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);
> 
> 
> -- 
> 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 opw-kernel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

      reply	other threads:[~2014-02-27 22:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <alpine.DEB.2.10.1402261908070.2159@hadrien>
     [not found] ` <20140226182832.GA23053@cloud>
     [not found]   ` <20140227164152.GA26266@kroah.com>
     [not found]     ` <20140227170811.GA28796@thin>
     [not found]       ` <alpine.DEB.2.10.1402271811010.4439@hadrien>
     [not found]         ` <20140227172017.GA29133@thin>
     [not found]           ` <alpine.DEB.2.10.1402271822540.4439@hadrien>
     [not found]             ` <1393523563.24588.101.camel@joe-AO722>
     [not found]               ` <alpine.DEB.2.10.1402271856530.4439@hadrien>
     [not found]                 ` <1393524256.24588.103.camel@joe-AO722>
     [not found]                   ` <20140227184723.GA3905@kroah.com>
2014-02-27 19:27                     ` [PATCH] checkpatch: Make "return is not a function" test quieter Joe Perches
2014-02-27 22:44                       ` josh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140227224401.GA30335@cloud \
    --to=josh@joshtriplett.org \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=monamagarwal123@gmail.com \
    --cc=opw-kernel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox