lkml.org 
[lkml]   [2013]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH -next] checkpatch: Warn only on "space before semicolon" at end of line
From
Date
The "space before a non-naked semicolon" test has
unwanted output when used in "for ( ;; )" loops.

Make the test work only on end-of-line statement
termination semicolons.

Signed-off-by: Joe Perches <joe@perches.com>
---
On Wed, 2013-12-04 at 11:21 +0300, Dan Carpenter wrote:
> You and I generally agree on style preferences...

True, and I think that's a good thing.

> I think the warning
> should be limited to grep " ;$".

Look at the output of:

$ git grep " ;" -- "*.[ch]" | grep -w for
...

The "| wc -l" output above in -next is
1407

Which of those should not be warned on?

$ git grep " ;" -- "*.[ch]" | grep -P "\bfor\s*\(\s+;" | wc -l
211

I think all of the uses like "for ( ; expression; expression)"
are unbalanced and should be avoided.

<I go off and look at checkpatch output>

Oh. checkpatch doesn't complain about spacing around
semicolon with for loops here. This error is a separate
test that looks only for space before semicolon.

So, we agree after all.

This test should look only for space before end-of-statement
semicolons at EOL.

This has still has false positives with multi-line fors like:

for ( ; expression ;
expression);

scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 38be5d5..d26eac6 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3131,7 +3131,7 @@ sub process {
}

# check for whitespace before a non-naked semicolon
- if ($line =~ /^\+.*\S\s+;/) {
+ if ($line =~ /^\+.*\S\s+;\s*$/) {
if (WARN("SPACING",
"space prohibited before semicolon\n" . $herecurr) &&
$fix) {



\
 
 \ /
  Last update: 2013-12-04 15:41    [W:0.050 / U:0.852 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site