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 V4 2/2] checkpatch: throw error for malformed arrays
Date: Sat, 22 Feb 2025 01:22:25 -0800	[thread overview]
Message-ID: <b150157b266b0aa78e26b1feb5a6b3d7735a2293.camel@perches.com> (raw)
In-Reply-To: <20250221182142.42134-3-trintaeoitogc@gmail.com>

On Fri, 2025-02-21 at 15:21 -0300, Guilherme Giacomo Simoes wrote:
> Implement a check to ensure these fields are correctly formatted. If a
> line contains one of these keys that should be of type Vec<String>, use
> a regex to verify whether the array holds multiple values.
> * If the array contains more than one value, enforce vertical formatting
> * If the array has only one value, it can remain on the same line

Malformed arrays of what type?

[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -2775,6 +2775,9 @@ sub process {
>  	$realcnt = 0;
>  	$linenr = 0;
>  	$fixlinenr = -1;
> +
> +	my %array_parse_module;
> +
>  	foreach my $line (@lines) {
>  		$linenr++;
>  		$fixlinenr++;
> @@ -3567,6 +3570,46 @@ 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

check if what kind of array otherwise this comment is very poor.
Arrays commonly have more than one value assigned on a single line like

	int foo[] = { 1, 2, 3 };

> +		my $inline = 0;
> +		my $key = "";
> +		my $add_line = $line =~ /^\+/;
> +
> +		if ($line =~ /\s*.*\b(authors|alias|firmware)\s*:\s*\[/) {

The initial "\s*.*" portion of this regex isn't necessary
and can be removed
=
> +			$inline = 1;
> +			$array_parse_module{$1} = 1;
> +		}
> +
> +		my @keys = keys %array_parse_module;
> +		if (@keys) {
> +			$key = $keys[0];
> +		}
> +
> +		if ($add_line && $key) {
> +			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
> +
> +			my $counter = () = $line =~ /"/g;
> +			my $more_than_one = $counter > 2;
> +			if ($more_than_one) {
> +				WARN("ARRAY_MODULE_MACRO",
> +				"Prefer each array element on a separate line\n$herevet");

As I wrote in an earlier submission, please align to open parenthesis
and use the common form for the message with $herevet

				WARN("ARRAY_MODULE_MACRO",
				     "Prefer each array element on a separate line\n" . $herevet);

> +			} elsif ($inline && $line !~ /\]/ && $line !~ /,/ && $line =~ /"/) {
> +				WARN("ARRAY_MODULE_MACRO",
> +				"Prefer declare ] on the same line\n$herevet");

etc...


  reply	other threads:[~2025-02-22  9:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 18:21 [PATCH V4 0/2] author field in module! macro should be a array Guilherme Giacomo Simoes
2025-02-21 18:21 ` [PATCH V4 1/2] rust: module: change author to an array Guilherme Giacomo Simoes
2025-02-21 18:21 ` [PATCH V4 2/2] checkpatch: throw error for malformed arrays Guilherme Giacomo Simoes
2025-02-22  9:22   ` Joe Perches [this message]
2025-02-22 13:30     ` Guilherme Giacomo Simoes
2025-02-23 14:34 [PATCH V5 " Joe Perches
2025-02-23 15:39 ` [PATCH V4 " 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=b150157b266b0aa78e26b1feb5a6b3d7735a2293.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®