[sheepdog] [PATCH v2 1/2] checkpatch: add more strict checking for block comments

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Mar 25 06:42:58 CET 2013


> +
> +		if ($rawline =~ /^\+.*\*\/\s*$/ &&
> +		    $rawline !~ /^\+.*\/\*/) {

This is a bit complex.  Can we write this as follows?

  if ($line =~ /^\+/ && $rawline =~ /\*\/$/ && $rawline !~ /\/\*/) {


> +			if ($rawline !~ /^\+\s*\*\/\s*$/) {

We already have a check to detect trailing spaces.  How about the
following?

   if ($rawline !~ /^\+\s*\*\/$/) {

> +				# case A and B
> +				WARN("BLOCK_COMMENT_STYLE",
> +				     "[BCS] put the trailing */ on a separate line\n" . $hereprev);
> +			} elsif ($prevrawline =~ /^\+\s*\/\*/ ||
> +				 $rawlines[$linenr - 3] =~ /^\+\s*\/\*/) {
> +				# case C and D
> +				WARN("BLOCK_COMMENT_STYLE",
> +				     "[BCS] don't use block comments for one liner comment\n" . $hereprev);
> +			} else {
> +				# case E
> +				my $ln = $linenr;
> +				while ($rawlines[$ln] !~ /^\+\s*\/\*/) { $ln--; }

We should add a guard like "$ln >= 0" to avoid infinite loop.

> +				if ($rawlines[$ln] !~ /^\+\s*\/\*\s*$/) {

Redundant check of trailing spaces.

  if ($rawlines[$ln] !~ /^\+\s*\/\*$/) {


Thanks,

Kazutaka



More information about the sheepdog mailing list