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

MORITA Kazutaka morita.kazutaka at gmail.com
Mon Jan 21 15:39:50 CET 2013


At Mon, 21 Jan 2013 11:47:40 +0900,
Hitoshi Mitake wrote:
> +
> +# 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/) {

/\b(case|default)/ looks simpler.

> +			my ($snlength, $snindent) = line_stats($sline);
> +			if ($nindent - 8 == $snindent) {

($nindent > $snindent) looks better to catch more errors.

> +			    ERROR("NL_AFTER_BREAK_IN_SWITCH",
> +				  "don't insert empty lines after break; line of switch statement" . $herecurr);

Add "\n" to the end of the second argument.

In addition, you patch allows the following.  Is it expected behavior?

+ switch (x) {
+ case A:
+ 	break;
+ default:
+ 	break; /* shouldn't this be an error? */
+ 
+ }

Thanks,

Kazutaka



More information about the sheepdog mailing list