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

Liu Yuan namei.unix at gmail.com
Mon Jan 21 06:45:41 CET 2013


On 01/21/2013 10:47 AM, Hitoshi Mitake wrote:
> 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
> 

I have virtual no knowledge of perl, Kazum, could you review this patch?

Thanks,
Yuan



More information about the sheepdog mailing list