All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Manfred Spraul <manfred@colorfullife.com>,
	Andy Whitcroft <apw@canonical.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/5] checkpatch: check for if's with unnecessary parentheses
Date: Thu, 26 Dec 2013 12:09:32 -0800	[thread overview]
Message-ID: <20131226200932.GC7267@leaf> (raw)
In-Reply-To: <c338a811bcaab4c3b684cf50575722af8d286865.1388085015.git.joe@perches.com>

On Thu, Dec 26, 2013 at 11:20:31AM -0800, Joe Perches wrote:
> If statements don't need multiple parentheses around tested
> comparisons like "if ((foo == bar))".
> 
> An == comparison maybe a sign of an intended assignment,
> so emit a slightly different message if so.
> 
> Signed-off-by: Joe Perches <joe@perches.com>

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

>  scripts/checkpatch.pl | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index db72b88..c12234e 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3322,6 +3322,20 @@ sub process {
>  			}
>  		}
>  
> +# if statements using unnecessary parentheses - ie: if ((foo == bar))
> +		if ($^V && $^V ge 5.10.0 &&
> +		    $line =~ /\bif\s*((?:\(\s*){2,})/) {
> +			my $openparens = $1;
> +			my $count = $openparens =~ tr@\(@\(@;
> +			my $msg = "";
> +			if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
> +				my $comp = $4;	#Not $1 because of $LvalOrFunc
> +				$msg = " - maybe == should be = ?" if ($comp eq "==");
> +				WARN("UNNECESSARY_PARENTHESES",
> +				     "Unnecessary parentheses$msg\n" . $herecurr);
> +			}
> +		}
> +
>  # Return of what appears to be an errno should normally be -'ve
>  		if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
>  			my $name = $1;
> -- 
> 1.8.1.2.459.gbcd45b4.dirty
> 

  reply	other threads:[~2013-12-26 20:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-26 19:20 [PATCH 0/5] checkpatch: A few corrections and updates Joe Perches
2013-12-26 19:20 ` [PATCH 1/5] checkpatch: Add tests for function pointer style misuses Joe Perches
2013-12-26 20:07   ` Josh Triplett
2013-12-27  0:58     ` Josh Triplett
2013-12-27  1:25       ` Joe Perches
2013-12-26 19:20 ` [PATCH 2/5] checkpatch: Add a --fix-inplace option Joe Perches
2013-12-26 20:08   ` Josh Triplett
2013-12-26 19:20 ` [PATCH 3/5] checkpatch: Improve space before tab --fix option Joe Perches
2013-12-26 19:20 ` [PATCH 4/5] checkpatch: check for if's with unnecessary parentheses Joe Perches
2013-12-26 20:09   ` Josh Triplett [this message]
2013-12-26 19:20 ` [PATCH 5/5] checkpatch: Update the FSF/GPL address check Joe Perches
  -- strict thread matches above, loose matches on Subject: below --
2013-12-26 22:16 + checkpatch-add-tests-for-function-pointer-style-misuses.patch added to -mm tree akpm

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=20131226200932.GC7267@leaf \
    --to=josh@joshtriplett.org \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.