Skip to contentSkip to conversation

checkpatch: Check for space after "else" keyword

PATCH Superseded Michal Zylowski 2 participants 2 messages Aug 5, 2018 Checkpatch

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch: Check for space after "else" keyword

Current checkpatch implementation permits notation like:
} else{
in kernel code.
It looks like oversight and inconsistency in checkpatch rules (e.g. instruction like 'do' is tested).

Add regex for checking space after 'else' keyword and trigger error if space is not present.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 447857f..81617b8 100755
@@ -4483,7 +4483,7 @@ sub process {
 
 #need space before brace following if, while, etc
 		if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
-		    $line =~ /do\{/) {
+		    $line =~ /\b(?:else|do)\{/) {
 			if (ERROR("SPACING",
 				  "space required before the open brace '{'\n" . $herecurr) &&
 			    $fix) {
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 19 lines · Michal Zylowski

Current checkpatch implementation permits notation like:
} else{
in kernel code.
It looks like oversight and inconsistency in checkpatch rules (e.g. instruction like 'do' is tested).

Add regex for checking space after 'else' keyword and trigger error if space is not present.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index 447857f..81617b8 100755

scripts/checkpatch.pl sub process { · line 4489

Quoted 8 lines
scripts/checkpatch.pl +1 -1
@@ -4483,7 +4483,7 @@ sub process {
 
 #need space before brace following if, while, etc
 		if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
-		    $line =~ /do\{/) {
+		    $line =~ /\b(?:else|do)\{/) {
 			if (ERROR("SPACING",
 				  "space required before the open brace '{'\n" . $herecurr) &&
 			    $fix) {

Thanks.

btw: the fix block blow also should be updated with else