linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dwaipayan Ray <dwaipayanray1@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 1/2] checkpatch: add verbose mode
Date: Mon, 22 Feb 2021 00:05:40 +0530	[thread overview]
Message-ID: <CABJPP5CJKUeaxUqKzuJD5pd2HsHKcAx9x3iCm6W+Z8AuXiR5Rg@mail.gmail.com> (raw)
In-Reply-To: <46c3b16602f36858b194b22dfbdb2150e25f5d94.camel@perches.com>

On Sun, Feb 21, 2021 at 11:36 PM Joe Perches <joe@perches.com> wrote:
>
> 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.

Okay, nice idea!
> 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);
>
>

Sure, I will do something like this.
Are there any other improvements you can see right now
or will the coloring thing suffice?

Thanks,
Dwaipayan

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

Thread overview: 7+ 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 ` [PATCH v6 1/2] " Dwaipayan Ray
2021-02-21 18:06   ` Joe Perches
2021-02-21 18:35     ` Dwaipayan Ray [this message]
2021-02-22  2:44       ` Joe Perches
2021-02-22  4:48         ` Dwaipayan Ray
2021-02-21 11:58 ` [PATCH v6 2/2] docs: add documentation for checkpatch 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=CABJPP5CJKUeaxUqKzuJD5pd2HsHKcAx9x3iCm6W+Z8AuXiR5Rg@mail.gmail.com \
    --to=dwaipayanray1@gmail.com \
    --cc=joe@perches.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).