[PATCH] checkpatch.pl: Fix checkpatch false positive due to ternary operator break

Subsystems: checkpatch, the rest

STALE4517d REVIEWED: 1 (0M)

1 review trailer.

2 messages, 2 authors, 2014-05-10 · open the first message on its own page

[PATCH] checkpatch.pl: Fix checkpatch false positive due to ternary operator break

From: Jeff Kirsher <hidden>
Date: 2014-05-10 04:41:55

From: David Ertman <redacted>

Using the intuitive breaking of a ternary operator used in the
initialization of a variable in its declaration:

type var = FOO ?
           BAR :
           FEE;

is causing a checkpatch warning:
"WARNING:SPACING: networking uses a blank line after declarations"

Checkpatch is checking for the ternary operators at the beginning of the
lines after the initial break like the following:

type var = FOO
           ? BAR
           : FEE;

Change checkpatch so that it is checking fot the correct breaking of ternary
operators used in networking variable declaration/initialization.

Signed-off-by: Dave Ertman <redacted>
Tested-by: Aaron Brown <redacted>
Signed-off-by: Jeff Kirsher <redacted>
---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 34eb216..baabf1c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2269,12 +2269,13 @@ sub process {
 		if ($realfile =~ m@^(drivers/net/|net/)@ &&
 		    $prevline =~ /^\+\s+$Declare\s+$Ident/ &&
 		    !($prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
-		      $prevline =~ /(?:\{\s*|\\)$/) &&		#extended lines
+		      $prevline =~ /(?:\{\s*|\\)$/ ||		#extended lines
+		      $prevline =~ /(?:[\?\:])$/) &&		#ternary ops
 		    $sline =~ /^\+\s+/ &&			#Not at char 1
 		    !($sline =~ /^\+\s+$Declare/ ||
 		      $sline =~ /^\+\s+$Ident\s+$Ident/ ||	#eg: typedef foo
 		      $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ ||
-		      $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(])/ ||
+		      $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\(])/ ||
 		      $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
 			WARN("SPACING",
 			     "networking uses a blank line after declarations\n" . $hereprev);
-- 
1.9.0

Re: [PATCH] checkpatch.pl: Fix checkpatch false positive due to ternary operator break

From: Joe Perches <joe@perches.com>
Date: 2014-05-10 04:47:22

On Fri, 2014-05-09 at 21:41 -0700, Jeff Kirsher wrote:
From: David Ertman <redacted>
Hey David.
Using the intuitive breaking of a ternary operator used in the
initialization of a variable in its declaration:

type var = FOO ?
           BAR :
           FEE;
[]
type var = FOO
           ? BAR
           : FEE;

Change checkpatch so that it is checking fot the correct breaking of ternary
operators used in networking variable declaration/initialization.
There is no "correct" breaking for ternary operators.
Both should be acceptable.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help