checkpatch: check for space after "else" keyword
authorMichal Zylowski <[email protected]>
Wed, 22 Aug 2018 04:58:08 +0000 (21:58 -0700)
committerLinus Torvalds <[email protected]>
Wed, 22 Aug 2018 17:52:49 +0000 (10:52 -0700)
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.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Michal Zylowski <[email protected]>
Acked-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
scripts/checkpatch.pl

index eced9b30399574b89ce66bf75662563bacffc0bb..f43d95a25712e59269f90044c1ed58862ffd7970 100755 (executable)
@@ -4531,11 +4531,11 @@ 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) {
-                               $fixed[$fixlinenr] =~ s/^(\+.*(?:do|\)))\{/$1 {/;
+                               $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
                        }
                }