Re: [PATCH v6 1/2] checkpatch: add verbose mode

From: Joe Perches
Date: Sun Feb 21 2021 - 13:12:36 EST


On Sun, 2021-02-21 at 17:28 +0530, Dwaipayan Ray wrote:
> Add a new verbose mode to checkpatch.pl to emit additional verbose
> test descriptions. The verbose mode is optional and can be enabled
> by the flag -v or --verbose.

OK, maybe add color coding to the list_types output.
Something like:
---
scripts/checkpatch.pl | 61 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index bbff13e0ca7e..ccd4a1bd73cb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -163,14 +163,39 @@ sub list_types {
my $text = <$script>;
close($script);

- my @types = ();
+ my %types = ();
# Also catch when type or level is passed through a variable
- for ($text =~ /(?:(?:\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
- push (@types, $_);
+ while ($text =~ /\b(CHK|WARN|ERROR|&\{\$msg_level})\s*\(\s*"([^"]+)"/g) {
+ if (exists($types{$2})) {
+ $types{$2} .= ",$1" if ($types{$2} ne $1);
+ } else {
+ $types{$2} = $1;
+ }
+ }
+ print("#\tMessage type");
+ if ($color) {
+ print(" (color coding: ");
+ print(RED . "ERROR" . RESET);
+ print("|");
+ print(YELLOW . "WARNING" . RESET);
+ print("|");
+ print(GREEN . "CHECK" . RESET);
+ print("|");
+ print("Multiple levels" . RESET);
+ print(")");
}
- @types = sort(uniq(@types));
- print("#\tMessage type\n\n");
- foreach my $type (@types) {
+ print("\n\n");
+ foreach my $type (sort keys %types) {
+ if ($color) {
+ my $level = $types{$type};
+ if ($level eq 'ERROR') {
+ $type = RED . $type . RESET;
+ } elsif ($level eq 'WARN') {
+ $type = YELLOW . $type . RESET;
+ } elsif ($level eq 'CHK') {
+ $type = GREEN . $type . RESET;
+ }
+ }
print(++$count . "\t" . $type . "\n");
if ($verbose && exists($verbose_messages{$type})) {
my $message = $verbose_messages{$type};
@@ -301,6 +326,18 @@ help(0) if ($help);
die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);

+if ($color =~ /^[01]$/) {
+ $color = !$color;
+} elsif ($color =~ /^always$/i) {
+ $color = 1;
+} elsif ($color =~ /^never$/i) {
+ $color = 0;
+} elsif ($color =~ /^auto$/i) {
+ $color = (-t STDOUT);
+} else {
+ die "$P: Invalid color mode: $color\n";
+}
+
load_docs() if ($verbose);
list_types(0) if ($list_types);

@@ -321,18 +358,6 @@ if ($#ARGV < 0) {
push(@ARGV, '-');
}

-if ($color =~ /^[01]$/) {
- $color = !$color;
-} elsif ($color =~ /^always$/i) {
- $color = 1;
-} elsif ($color =~ /^never$/i) {
- $color = 0;
-} elsif ($color =~ /^auto$/i) {
- $color = (-t STDOUT);
-} else {
- die "$P: Invalid color mode: $color\n";
-}
-
# skip TAB size 1 to avoid additional checks on $tabsize - 1
die "$P: Invalid TAB size: $tabsize\n" if ($tabsize < 2);