From: Christoph Hellwig <hch@lst.de>
To: apw@canonical.com, joe@perches.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: make the line length warnings match the coding style document
Date: Thu, 10 Dec 2020 09:22:51 +0100 [thread overview]
Message-ID: <20201210082251.2717564-1-hch@lst.de> (raw)
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
next reply other threads:[~2020-12-10 8:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-10 8:22 Christoph Hellwig [this message]
2020-12-10 20:05 ` Joe Perches
2020-12-10 20:09 ` Matthew Wilcox
2020-12-10 21:27 ` Joe Perches
2020-12-22 4:08 ` Joe Perches
2020-12-22 13:12 ` Christoph Hellwig
2020-12-22 16:22 ` Joe Perches
2020-12-23 8:29 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201210082251.2717564-1-hch@lst.de \
--to=hch@lst.de \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®