[sheepdog] [PATCH v2] checkpatch.pl: forbid empty lines after break; line of switch statements

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Jan 21 03:47:40 CET 2013


From: Hitoshi Mitake <h.mitake at gmail.com>

This patch lets checkpatch.pl forbid empty lines after break; line of
switch statements.

For example, a patch which contains diffs like this:
+	switch (s) {
+	case 0:
+		break;
+	case 1:
+		break;		/* this should be treated as error */
+
+	default:
+		break;
+	}
causes an error.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 script/checkpatch.pl |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/script/checkpatch.pl b/script/checkpatch.pl
index 48917af..d490313 100755
--- a/script/checkpatch.pl
+++ b/script/checkpatch.pl
@@ -2841,9 +2841,31 @@ sub process {
 			}
 		}
 
+# forbid bzero()
 		if ($line =~ /\bbzero\(/) {
 			ERROR("BZERO", "bzero() is obsolete, use memset()" . $herecurr);
 		}
+
+# forbid empty lines after break; line of switch statement
+# e.g.
+# +        break;
+# +
+# +    case XXX:
+		if ($line =~ /\bbreak;/) {
+		    my ($nlength, $nindent) = line_stats($line);
+
+		    my $ln = $linenr + 1;
+		    while ($lines[$ln] =~ /^\+$/) { $ln++; }
+		    my $sline = $lines[$ln];
+
+		    if ($sline =~ /\bcase/ ||  $sline =~ /\bdefault/) {
+			my ($snlength, $snindent) = line_stats($sline);
+			if ($nindent - 8 == $snindent) {
+			    ERROR("NL_AFTER_BREAK_IN_SWITCH",
+				  "don't insert empty lines after break; line of switch statement" . $herecurr);
+			}
+		    }
+		}
 	}
 
 	# If we have no input at all, then there is nothing to report on
-- 
1.7.2.5




More information about the sheepdog mailing list