[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d2fe8cfc-df97-4947-bcbc-7d43b5c24ecc@sedlak.dev>
Date: Sat, 8 Mar 2025 19:30:47 +0100
From: Daniel Sedlak <daniel@...lak.dev>
To: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>,
a.hindborg@...nel.org, alex.gaynor@...il.com, aliceryhl@...gle.com,
apw@...onical.com, arnd@...db.de, aswinunni01@...il.com, axboe@...nel.dk,
benno.lossin@...ton.me, bhelgaas@...gle.com, bjorn3_gh@...tonmail.com,
boqun.feng@...il.com, dakr@...nel.org, dwaipayanray1@...il.com,
ethan.twardy@...il.com, fujita.tomonori@...il.com, gary@...yguo.net,
gregkh@...uxfoundation.org, joe@...ches.com, lukas.bulwahn@...il.com,
ojeda@...nel.org, pbonzini@...hat.com, tmgross@...ch.edu,
walmeida@...rosoft.com, charmitro@...teo.net
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH V7 2/2] checkpatch: check format of Vec<String> in modules
On 3/7/25 2:14 PM, Guilherme Giacomo Simoes wrote:
> Implement a check to ensure that the author, firmware, and alias fields
> of the module! macro are properly formatted.
>
> * If the array contains more than one value, enforce vertical
> formatting.
> * If the array contains only one value, it may be formatted on a single
> line
>
> Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
> ---
> scripts/checkpatch.pl | 67 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 67 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7b28ad331742..7c42c1a0ea6b 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2775,6 +2775,12 @@ sub process {
> $realcnt = 0;
> $linenr = 0;
> $fixlinenr = -1;
> +
> + my %array_parse_module;
> + my $expected_spaces;
> + my $spaces;
> + my $herevet_space_add;
> +
> foreach my $line (@lines) {
> $linenr++;
> $fixlinenr++;
> @@ -3567,6 +3573,67 @@ sub process {
> # ignore non-hunk lines and lines being removed
> next if (!$hunk_line || $line =~ /^-/);
>
> +# check if the field is about author, firmware or alias from module! macro and find malformed arrays
> + my $inline = 0;
> + my $key = "";
> + my $add_line = $line =~ /^\+/;
> +
> + if ($line =~ /\b(authors|alias|firmware)\s*:\s*\[/) {
> + $inline = 1;
> + $array_parse_module{$1} = 1;
> + }
> +
> + my @keys = keys %array_parse_module;
> + if (@keys) {
> + $key = $keys[0];
> + }
> +
> + if (!$expected_spaces && (!$add_line && $key && !$inline)) {
> + if ($line =~ /^([\t ]+)(\s)/) {
> + $expected_spaces = $1;
> + }
> + }
> +
> + 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);
> + } elsif ($inline && $line !~ /\]/ && $line !~ /,/ && $line =~ /"/) {
> + WARN("ARRAY_MODULE_MACRO",
> + "Prefer declare ] on the same line\n" . $herevet);
Small grammar nit. "Prefer to declare…"
> + } elsif (!$inline && $line =~ /\]/ && $line =~ /\"/) {
> + WARN("ARRAY_MODULE_MACRO",
> + "Prefer a new line after the last value and before ]\n" . $herevet);
> + } elsif ($inline && $line =~ /,/ && $line !~ /\]/) {
> + WARN("ARRAY_MODULE_MACRO",
> + "Prefer a new line after [\n" . $herevet);
> + }
> +
> + if ($line =~ /^\+\s*([\t ]+)(\S)/) {
> + $spaces = $1;
> + $herevet_space_add = $herevet;
> + }
> + }
> +
> + if ($expected_spaces && $spaces) {
> + if (length($spaces) != length($expected_spaces)) {
> + WARN("ARRAY_MODULE_MACRO",
> + "Prefer a align parameters\n" . $herevet_space_add);
Small grammar nit. Shouldn't this be rather: "Prefer to align
parameters" or "Prefer aligned parameters"?
> + }
> +
> + $spaces = undef;
> + }
> +
> + #END OF ANALYZE FIELD
> + if ($line =~ /\]/) {
> + delete $array_parse_module{$key};
> + $expected_spaces = undef;
> + }
> +
> #trailing whitespace
> if ($line =~ /^\+.*\015/) {
> my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Powered by blists - more mailing lists