[PATCH -next] checkpatch: Warn only on "space before semicolon" atend of line

From: Joe Perches
Date: Wed Dec 04 2013 - 08:47:59 EST


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@xxxxxxxxxxx>
---
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) {


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/