Messages in this thread Patch in this message | | | From | Christoph Hellwig <> | Subject | [PATCH] checkpatch: make the line length warnings match the coding style document | Date | Thu, 10 Dec 2020 09:22:51 +0100 |
| |
Add a new informational message that lines <= 80 chars are still preffered. Without this people unfortunately auto format code way over 80 lines without the required benefit for readability.
Signed-off-by: Christoph Hellwig <hch@lst.de> --- scripts/checkpatch.pl | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index fab38b493cef79..d937889a5fe3b2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -54,6 +54,7 @@ my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; my $max_line_length = 100; +my $preferred_line_length = 80; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; @@ -2228,6 +2229,16 @@ sub WARN { } return 0; } +sub INFO { + my ($type, $msg) = @_; + + if (report("INFO", $type, $msg)) { + our $clean = 0; + our $cnt_info++; + return 1; + } + return 0; +} sub CHK { my ($type, $msg) = @_; @@ -2396,6 +2407,7 @@ sub process { our $cnt_lines = 0; our $cnt_error = 0; our $cnt_warn = 0; + our $cnt_info = 0; our $cnt_chk = 0; # Trace the real file/line as we go. @@ -3343,15 +3355,15 @@ sub process { # if LONG_LINE is ignored, the other 2 types are also ignored # - if ($line =~ /^\+/ && $length > $max_line_length) { + if ($line =~ /^\+/ && $length > $preferred_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 + # before $preferred_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) { + length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $preferred_line_length) { $msg_type = ""; # lines with only strings (w/ possible termination) @@ -3371,23 +3383,30 @@ sub process { # Otherwise set the alternate message types - # a comment starts before $max_line_length + # a comment starts before $preferred_line_length } elsif ($line =~ /($;[\s$;]*)$/ && - length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) { + length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $preferred_line_length) { $msg_type = "LONG_LINE_COMMENT" - # a quoted string starts before $max_line_length + # a quoted string starts before $preferred_line_length } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ && - length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) { + length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $preferred_line_length) { $msg_type = "LONG_LINE_STRING" } if ($msg_type ne "" && (show_type("LONG_LINE") || show_type($msg_type))) { - my $msg_level = \&WARN; - $msg_level = \&CHK if ($file); - &{$msg_level}($msg_type, + my $msg_level = \&CHK; + + if ($line =~ /^\+/ && $length <= $max_line_length) { + $msg_level = \&INFO if (!$file); + &{$msg_level}($msg_type, + "line length of $length exceeds preferred $preferred_line_length columns\n" . $herecurr); + } else { + $msg_level = \&WARN if (!$file); + &{$msg_level}($msg_type, "line length of $length exceeds $max_line_length columns\n" . $herecurr); + } } } @@ -7015,7 +7034,7 @@ sub process { print report_dump(); if ($summary && !($clean == 1 && $quiet == 1)) { print "$filename " if ($summary_file); - print "total: $cnt_error errors, $cnt_warn warnings, " . + print "total: $cnt_error errors, $cnt_warn warnings, $cnt_info informational, " . (($check)? "$cnt_chk checks, " : "") . "$cnt_lines lines checked\n"; } -- 2.29.2
| |