Skip to contentSkip to conversation

checkpatch: suggest spaces around binary operators in strict mode

PATCH In review Pavel Roskin 2 participants 3 messages Jul 8, 2011 – Jul 9, 2011 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: suggest spaces around binary operators in strict mode

---
 scripts/checkpatch.pl |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +2 -0
index b0aa2c6..9431ada 100755
@@ -2167,6 +2167,8 @@ sub process {
 					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
 						ERROR("need consistent spacing around '$op' $at\n" .
 							$hereptr);
+					} elsif ($ctx =~ /[^WCE]x[^WCE]/) {
+						CHK("spaces suggested around '$op' $at\n" . $hereptr);
 					}
 
 				# A colon needs no spaces before when it is
maintainer
#1 lore raw
Quoted 10 lines · Pavel Roskin
---
 scripts/checkpatch.pl |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +0 -0
index b0aa2c6..9431ada 100755

scripts/checkpatch.pl sub process { · line 2171

Quoted 5 lines
scripts/checkpatch.pl +2 -0
@@ -2167,6 +2167,8 @@ sub process {
 					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
 						ERROR("need consistent spacing around '$op' $at\n" .
 							$hereptr);
+					} elsif ($ctx =~ /[^WCE]x[^WCE]/) {
+						CHK("spaces suggested around '$op' $at\n" . $hereptr);

Hey Pavel.

This should probably not be an elsif but
a standalone test.

Also, there's an upcoming patch in mm that
classifies all output ERROR/WARN/CHK types.

This one should be "SPACING".

https://lkml.org/lkml/2011/6/21/256

http://userweb.kernel.org/~akpm/mmotm/broken-out/checkpatchpl-add-ability-to-ignore-various-messages.patch

#2 lore raw
Quoted 19 lines · Joe Perches
Quoted 10 lines · Pavel Roskin
---
  scripts/checkpatch.pl |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +0 -0
index b0aa2c6..9431ada 100755

scripts/checkpatch.pl sub process { · line 2171

Quoted 5 lines
scripts/checkpatch.pl +2 -0
@@ -2167,6 +2167,8 @@ sub process {
  					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
  						ERROR("need consistent spacing around '$op' $at\n" .
  							$hereptr);
+					} elsif ($ctx =~ /[^WCE]x[^WCE]/) {
+						CHK("spaces suggested around '$op' $at\n" . $hereptr);

Hey Pavel.

Quoted 2 lines

This should probably not be an elsif but
a standalone test.

Maybe. I just tried to minimize the changes. I think all of the operators in the condition above the lines I changed need spaces around them, so I decided to reuse the code block.

Spaces around binary operands are pretty standard. scripts/Lindent would add them.

I understand that not everybody wants that rule enforced, so I used a nicely worded warning and enabled it only in the strict mode. That was done to avoid sparking a flamewar about formatting.

There are some cases when missing spaces are palatable, in particular with "|", which is thin. So this may be OK:

(high_id << 8)|(low_id & 0xff)

But I've seen checkpatch ignore stuff like this:

ah->ah_gain.g_current-ah->ah_gain.g_f_corr

And that is just horrible on the eyes. I want checkpatch to catch that.

Quoted 4 lines

Also, there's an upcoming patch in mm that
classifies all output ERROR/WARN/CHK types.

This one should be "SPACING".

OK, please keep my suggestion in mind.

Signature · 2 lines
Regards,
Pavel Roskin