public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@shadowen.org>
To: Eugene Teo <eugeneteo@kernel.sg>
Cc: linux-kernel@vger.kernel.org, auke-jan.h.kok@intel.com
Subject: Re: [PATCH] Make checkpatch rant about trailing ; at the end of "if" expr
Date: Thu, 16 Aug 2007 10:21:52 +0100	[thread overview]
Message-ID: <46C41730.3060009@shadowen.org> (raw)
In-Reply-To: <20070816052215.GA3857@kernel.sg>

Eugene Teo wrote:
> Make checkpatch rant about trailing ; at the end of "if" expression.
> 
> Thanks to Auke for the regexp.
> 
> Signed-off by: Eugene Teo <eugeneteo@kernel.sg>
> 
> --- checkpatch.pl-0.09.default	2007-08-03 23:31:40.000000000 +0800
> +++ checkpatch.pl-0.09	2007-08-16 13:18:40.000000000 +0800
> @@ -1091,6 +1091,12 @@ sub process {
>  				CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
>  			}
>  		}
> +
> +# checks for trailing ; at the end of "if" expression
> +		if ($line =~ /\bif\s*\([^\)]*\)\s*\;/) {
> +			my $herevet = "$here\n" . cat_vet($line) . "\n";
> +			ERROR("trailing ;\n" . $herevet);
> +		}
>  	}
>  
>  	if ($chk_patch && !$is_patch) {

Heh, you are the second person to suggest this check today, do I detect
some ripped out hair due to one of these!

I've taken this idea and expanded it to cover if, for and while which
can all suffer from this.  Using the relative indent to work out which
are valid combinations:

WARNING: Trailing semicolon indicates no statements, indent implies
otherwise
#28: FILE: Z17.c:25:
+       if (foo);
+               return 10;
WARNING: Trailing semicolon indicates no statements, indent implies
otherwise
#31: FILE: Z17.c:28:
+       for (a; b; c);
+               a += *b;

Thanks for the patch.

-apw

  reply	other threads:[~2007-08-16  9:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16  5:22 [PATCH] Make checkpatch rant about trailing ; at the end of "if" expr Eugene Teo
2007-08-16  9:21 ` Andy Whitcroft [this message]
2007-08-17 12:03   ` Jan Engelhardt
     [not found] <8SGSb-2Kk-9@gated-at.bofh.it>
     [not found] ` <8SJQ6-7pj-13@gated-at.bofh.it>
     [not found]   ` <8T8Oy-3D0-13@gated-at.bofh.it>
2007-08-20 11:52     ` Bodo Eggert
2007-08-20 12:44       ` Jan Engelhardt
2007-08-22  9:21         ` Bodo Eggert
2007-08-22  9:57           ` Jan Engelhardt

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=46C41730.3060009@shadowen.org \
    --to=apw@shadowen.org \
    --cc=auke-jan.h.kok@intel.com \
    --cc=eugeneteo@kernel.sg \
    --cc=linux-kernel@vger.kernel.org \
    /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