Skip to content

Commit

Permalink
checkpatch: categorize some long line length checks
Browse files Browse the repository at this point in the history
Many lines of code extend beyond the maximum line length.  Some of these
are possibly justified by use type.

For instance:

structure definitions where comments are added per member like:
struct foo {
	type member;		/* some long description */

And lines that don't fit the typical logging message style
where a string constant is used like:

        SOME_MACRO(args, "Some long string");

Categorize these long line types so that checkpatch can use a command-line
--ignore=<type> option to avoid emitting some long line warnings.

One of the existing checkpatch exclusions allowed kernel-doc argument
documentation to exceed 80 columns because old versions of kernel-doc
required single line documentation.  The requirement was removed in 2009
so remove that exclusion.

Add documentation to make the test a bit clearer.

Signed-off-by: Joe Perches <joe@perches.com>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Cc: Michael Shuey <shuey@purdue.edu>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
JoePerches authored and torvalds committed Jun 26, 2015
1 parent 33acb54 commit 47e0c88
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2517,16 +2517,56 @@ sub process {
# check we are in a valid source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|s|S|pl|sh|dtsi|dts)$/);

#line length limit
if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
$rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
!($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?$String\s*(?:|,|\)\s*;)\s*$/ ||
$line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
$line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) &&
$length > $max_line_length)
{
WARN("LONG_LINE",
"line over $max_line_length characters\n" . $herecurr);
# line length limit (with some exclusions)
#
# There are a few types of lines that may extend beyond $max_line_length:
# logging functions like pr_info that end in a string
# lines with a single string
# #defines that are a single string
#
# There are 3 different line length message types:
# LONG_LINE_COMMENT a comment starts before but extends beyond $max_linelength
# LONG_LINE_STRING a string starts before but extends beyond $max_line_length
# LONG_LINE all other lines longer than $max_line_length
#
# if LONG_LINE is ignored, the other 2 types are also ignored
#

if ($length > $max_line_length) {
my $msg_type = "LONG_LINE";

# Check the allowed long line types first

# logging functions that end in a string that starts
# before $max_line_length
if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
$msg_type = "";

# lines with only strings (w/ possible termination)
# #defines with only strings
} elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
$line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
$msg_type = "";

# Otherwise set the alternate message types

# a comment starts before $max_line_length
} elsif ($line =~ /($;[\s$;]*)$/ &&
length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
$msg_type = "LONG_LINE_COMMENT"

# a quoted string starts before $max_line_length
} elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
$msg_type = "LONG_LINE_STRING"
}

if ($msg_type ne "" &&
(show_type("LONG_LINE") || show_type($msg_type))) {
WARN($msg_type,
"line over $max_line_length characters\n" . $herecurr);
}
}

# check for adding lines without a newline.
Expand Down

0 comments on commit 47e0c88

Please sign in to comment.