All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: lukas.bulwahn@gmail.com,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 1/2] checkpatch: add verbose mode
Date: Sun, 21 Feb 2021 10:06:43 -0800	[thread overview]
Message-ID: <46c3b16602f36858b194b22dfbdb2150e25f5d94.camel@perches.com> (raw)
In-Reply-To: <20210221115802.19788-2-dwaipayanray1@gmail.com>

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);
 


WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [Linux-kernel-mentees] [PATCH v6 1/2] checkpatch: add verbose mode
Date: Sun, 21 Feb 2021 10:06:43 -0800	[thread overview]
Message-ID: <46c3b16602f36858b194b22dfbdb2150e25f5d94.camel@perches.com> (raw)
In-Reply-To: <20210221115802.19788-2-dwaipayanray1@gmail.com>

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);
 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2021-02-21 18:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21 11:58 [PATCH v6 0/2] checkpatch: add verbose mode Dwaipayan Ray
2021-02-21 11:58 ` [Linux-kernel-mentees] " Dwaipayan Ray
2021-02-21 11:58 ` [PATCH v6 1/2] " Dwaipayan Ray
2021-02-21 11:58   ` [Linux-kernel-mentees] " Dwaipayan Ray
2021-02-21 18:06   ` Joe Perches [this message]
2021-02-21 18:06     ` Joe Perches
2021-02-21 18:35     ` Dwaipayan Ray
2021-02-21 18:35       ` [Linux-kernel-mentees] " Dwaipayan Ray
2021-02-22  2:44       ` Joe Perches
2021-02-22  2:44         ` [Linux-kernel-mentees] " Joe Perches
2021-02-22  4:48         ` Dwaipayan Ray
2021-02-22  4:48           ` [Linux-kernel-mentees] " Dwaipayan Ray
2021-02-21 11:58 ` [PATCH v6 2/2] docs: add documentation for checkpatch Dwaipayan Ray
2021-02-21 11:58   ` [Linux-kernel-mentees] " Dwaipayan Ray

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=46c3b16602f36858b194b22dfbdb2150e25f5d94.camel@perches.com \
    --to=joe@perches.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.