mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>,
	a.hindborg@kernel.org, 	alex.gaynor@gmail.com,
	aliceryhl@google.com, apw@canonical.com, arnd@arndb.de,
		aswinunni01@gmail.com, axboe@kernel.dk, benno.lossin@proton.me,
		bhelgaas@google.com, bjorn3_gh@protonmail.com,
	boqun.feng@gmail.com, 	dakr@kernel.org, dwaipayanray1@gmail.com,
	ethan.twardy@gmail.com, 	fujita.tomonori@gmail.com,
	gary@garyguo.net, gregkh@linuxfoundation.org,
		lukas.bulwahn@gmail.com, ojeda@kernel.org, pbonzini@redhat.com,
	tmgross@umich.edu, 	walmeida@microsoft.com
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] checkpatch: throw error in malformed arrays
Date: Thu, 13 Feb 2025 03:17:09 -0800	[thread overview]
Message-ID: <3a6b43bad48592887d4e67ca854eef2728464b1c.camel@perches.com> (raw)
In-Reply-To: <20250212194857.192057-2-trintaeoitogc@gmail.com>

On Wed, 2025-02-12 at 16:48 -0300, Guilherme Giacomo Simoes wrote:
> In module! macro, some fields have a string array type, and we need a
> check for guarantee a good formatation.

Isn't this is a style desire not a parsing limitation?

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -2775,6 +2775,9 @@ sub process {
>  	$realcnt = 0;
>  	$linenr = 0;
>  	$fixlinenr = -1;
> +
> +	my %parse_module_arr;

Probably not useful to add hungarian style naming.

> @@ -3567,6 +3570,71 @@ sub process {
>  # ignore non-hunk lines and lines being removed
>  		next if (!$hunk_line || $line =~ /^-/);
>  
> +# check if arrays has more than one value in the same line
> +		my $inline = 0;
> +		if ($line =~ /^\+\s*.*\b(author|alias|firmware)\s*:\s*\[/) {

\s*.* could be just .*

> +			$inline = 1;
> +
> +			if ($line =~ /author/) {
> +				$parse_module_arr{'author'} = 1;
> +			}
> +
> +			if ($line =~ /alias/) {
> +				$parse_module_arr{'alias'} = 1;
> +			}
> +
> +			if ($line =~ /firmware/) {
> +				$parse_module_arr{'firmware'} = 1;
> +			}

$parse_module_arr{$1} = 1;

> +		}
> +
> +		if (keys %parse_module_arr) {
> +			my @keys = keys %parse_module_arr;
> +			my $key = $keys[0];
> +
> +			my $more_than_one_vl = qr/".+",\s*".+"/;
> +
> +			if ($line =~ $more_than_one_vl) {
> +					ERROR("ERR_ARRAY_MODULE_MACRO",
> +						"the key $key have more than one values in same line\n$here\n". cat_vet($rawline));

"Prefer one value per line\n"

ERR_ error prefixes are not useful.
These seem more like a WARN than an ERROR
Bad indentation
And please use a $herevet temporary


> +			}
> +			elsif ($inline && $line !~ /\]/ && $line =~ /\["/) {
> +					ERROR("ERR_ARRAY_MODULE_MACRO",
> +						qq~the key $key need a new line after declare the key\n$here\n~ . cat_vet($rawline) . qq~\nFor example:

Use } elsif

"Prefer declaring keys on separate lines"

Are quote characters allowed in keys?
If not, this seems unnecessarily complicated.

$herevet

I think the qq is unnecessary and the for example
should refer to some style documentation and not
be explicit in checkpatch.


  reply	other threads:[~2025-02-13 11:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12 19:48 [PATCH 2/3] rust: macros: change author field to array Guilherme Giacomo Simoes
2025-02-12 19:48 ` [PATCH 3/3] checkpatch: throw error in malformed arrays Guilherme Giacomo Simoes
2025-02-13 11:17   ` Joe Perches [this message]
2025-02-13 18:20     ` Guilherme Giacomo Simoes
2025-02-13 11:34 ` [PATCH 2/3] rust: macros: change author field to array Gary Guo
2025-02-13 17:46   ` Guilherme Giacomo Simoes

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=3a6b43bad48592887d4e67ca854eef2728464b1c.camel@perches.com \
    --to=joe@perches.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apw@canonical.com \
    --cc=arnd@arndb.de \
    --cc=aswinunni01@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=benno.lossin@proton.me \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dwaipayanray1@gmail.com \
    --cc=ethan.twardy@gmail.com \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=trintaeoitogc@gmail.com \
    --cc=walmeida@microsoft.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

all inboxes | Powered by JetHome®