Skip to contentSkip to conversation

scripts/checkpatch.pl: Don't allow special cases of unspaced operators

PATCH Applied Peter Maydell 5 participants 5 messages Dec 18, 2015 – Jan 11, 2016 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/checkpatch.pl: Don't allow special cases of unspaced operators

The checkpatch.pl script has a special case to permit the following operators to have no spaces around them:
<< >> & ^ | + - * / %

QEMU style prefers all operators to consistently have spacing around them, so remove this special case handling. This avoids reviewers having to manually note it during code review.

---
I actually thought failing to point out the lack of spaces was a checkpatch parsing bug until I looked in the source and found it was deliberate...

I say "QEMU style prefers", but possibly what I actually mean is "I prefer" ? Does anybody want to defend the unspaced versions?

 scripts/checkpatch.pl | 13 -------------
 1 file changed, 13 deletions(-)
scripts/checkpatch.pl +0 -13
index b0f6e11..efca817 100755
@@ -1890,19 +1890,6 @@ sub process {
 						ERROR("space prohibited after that '$op' $at\n" . $hereptr);
 					}
 
-
-				# << and >> may either have or not have spaces both sides
-				} elsif ($op eq '<<' or $op eq '>>' or
-					 $op eq '&' or $op eq '^' or $op eq '|' or
-					 $op eq '+' or $op eq '-' or
-					 $op eq '*' or $op eq '/' or
-					 $op eq '%')
-				{
-					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
-						ERROR("need consistent spacing around '$op' $at\n" .
-							$hereptr);
-					}
-
 				# A colon needs no spaces before when it is
 				# terminating a case value or a label.
 				} elsif ($opv eq ':C' || $opv eq ':L') {
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines · Peter Maydell

The checkpatch.pl script has a special case to permit the following operators to have no spaces around them:
<< >> & ^ | + - * / %

QEMU style prefers all operators to consistently have spacing around them, so remove this special case handling. This avoids reviewers having to manually note it during code review.

Quoted 8 lines

---
I actually thought failing to point out the lack of spaces was a checkpatch parsing bug until I looked in the source and found it was deliberate...

I say "QEMU style prefers", but possibly what I actually mean is "I prefer" ? Does anybody want to defend the unspaced versions?

No thanks. Let's save to bikeshedding for important stuff such as line lengths. :)

Paolo

Quoted 28 lines
 scripts/checkpatch.pl | 13 -------------
 1 file changed, 13 deletions(-)
scripts/checkpatch.pl +0 -13
index b0f6e11..efca817 100755
@@ -1890,19 +1890,6 @@ sub process {
 						ERROR("space prohibited after that '$op' $at\n" . $hereptr);
 					}
 
-
-				# << and >> may either have or not have spaces both sides
-				} elsif ($op eq '<<' or $op eq '>>' or
-					 $op eq '&' or $op eq '^' or $op eq '|' or
-					 $op eq '+' or $op eq '-' or
-					 $op eq '*' or $op eq '/' or
-					 $op eq '%')
-				{
-					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
-						ERROR("need consistent spacing around '$op' $at\n" .
-							$hereptr);
-					}
-
 				# A colon needs no spaces before when it is
 				# terminating a case value or a label.
 				} elsif ($opv eq ':C' || $opv eq ':L') {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell

Am 18.12.2015 um 13:59 schrieb Peter Maydell:

Quoted 8 lines

The checkpatch.pl script has a special case to permit the following operators to have no spaces around them:
<< >> & ^ | + - * / %

QEMU style prefers all operators to consistently have spacing around them, so remove this special case handling. This avoids reviewers having to manually note it during code review.

Quoted 8 lines

---
I actually thought failing to point out the lack of spaces was a checkpatch parsing bug until I looked in the source and found it was deliberate...

I say "QEMU style prefers", but possibly what I actually mean is "I prefer" ? Does anybody want to defend the unspaced versions?

I don't. Therefore

Cc'ing QEMU Trivial, maybe it can be applied there.

Quoted 29 lines
 scripts/checkpatch.pl | 13 -------------
 1 file changed, 13 deletions(-)
scripts/checkpatch.pl +0 -13
index b0f6e11..efca817 100755
@@ -1890,19 +1890,6 @@ sub process {
 						ERROR("space prohibited after that '$op' $at\n" . $hereptr);
 					}
 
-
-				# << and >> may either have or not have spaces both sides
-				} elsif ($op eq '<<' or $op eq '>>' or
-					 $op eq '&' or $op eq '^' or $op eq '|' or
-					 $op eq '+' or $op eq '-' or
-					 $op eq '*' or $op eq '/' or
-					 $op eq '%')
-				{
-					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
-						ERROR("need consistent spacing around '$op' $at\n" .
-							$hereptr);
-					}
-
 				# A colon needs no spaces before when it is
 				# terminating a case value or a label.
 				} elsif ($opv eq ':C' || $opv eq ':L') {
Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Maydell
Quoted 8 lines · Peter Maydell

The checkpatch.pl script has a special case to permit the following operators to have no spaces around them:
<< >> & ^ | + - * / %

QEMU style prefers all operators to consistently have spacing around them, so remove this special case handling. This avoids reviewers having to manually note it during code review.

Quoted 8 lines

---
I actually thought failing to point out the lack of spaces was a checkpatch parsing bug until I looked in the source and found it was deliberate...

I say "QEMU style prefers", but possibly what I actually mean is "I prefer" ? Does anybody want to defend the unspaced versions?

I'm in favor of this patch; it only affects new code, and explains why I have been spotting unspaced operators in new code that didn't trigger checkpatch noise.

Quoted 10 lines
 scripts/checkpatch.pl | 13 -------------
 1 file changed, 13 deletions(-)
scripts/checkpatch.pl +0 -0
index b0f6e11..efca817 100755
@@ -1890,19 +1890,6 @@ sub process {
 						ERROR("space prohibited after that '$op' $at\n" . $hereptr);

scripts/checkpatch.pl sub process { · line 1900

Quoted 10 lines
scripts/checkpatch.pl +0 -8
 					}
 
-
-				# << and >> may either have or not have spaces both sides
-				} elsif ($op eq '<<' or $op eq '>>' or
-					 $op eq '&' or $op eq '^' or $op eq '|' or
-					 $op eq '+' or $op eq '-' or
-					 $op eq '*' or $op eq '/' or
-					 $op eq '%')
-				{

What's weird is that the comment wasn't even correct. Probably one person special-cased << and >>, and another then extended to special-case all operators.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell

The checkpatch.pl script has a special case to permit the following operators to have no spaces around them:
<< >> & ^ | + - * / %

QEMU style prefers all operators to consistently have spacing around them, so remove this special case handling. This avoids reviewers having to manually note it during code review.

Applied to -trivial, thank you!

/mjt