Skip to content

Commit

Permalink
checkpatch: test multiple line block comment alignment
Browse files Browse the repository at this point in the history
Warn when block comments are not aligned on the *

/*
 * block comment, no warning
 */

/*
  * block comment, emit warning
  */

Link: http://lkml.kernel.org/r/edb57bd330adfe024b95ec2a807d4aa7f0c8b112.1472261299.git.joe@perches.com
Signed-off-by: Joe Perches <[email protected]>
Reported-by: Sudip Mukherjee <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Oct 11, 2016
1 parent f90774e commit 08eb9b8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2979,6 +2979,25 @@ sub process {
"Block comments use a trailing */ on a separate line\n" . $herecurr);
}

# Block comment * alignment
if ($prevline =~ /$;[ \t]*$/ && #ends in comment
(($prevrawline =~ /^\+.*?\/\*/ && #starting /*
$prevrawline !~ /\*\/[ \t]*$/) || #no trailing */
$prevrawline =~ /^\+[ \t]*\*/) && #starting *
$rawline =~ /^\+[ \t]*\*/) { #rawline *
$prevrawline =~ m@^\+([ \t]*/?)\*@;
my $oldindent = expand_tabs($1);
$rawline =~ m@^\+([ \t]*)\*@;
my $newindent = $1;
my $test_comment = '^\\+' . "$;" x (length($newindent) + 1);
$newindent = expand_tabs($newindent);
if ($line =~ /$test_comment/ &&
length($oldindent) ne length($newindent)) {
WARN("BLOCK_COMMENT_STYLE",
"Block comments should align the * on each line\n" . $hereprev);
}
}

# check for missing blank lines after struct/union declarations
# with exceptions for various attributes and macros
if ($prevline =~ /^[\+ ]};?\s*$/ &&
Expand Down

0 comments on commit 08eb9b8

Please sign in to comment.