From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: 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, joe@perches.com,
lukas.bulwahn@gmail.com, ojeda@kernel.org, pbonzini@redhat.com,
tmgross@umich.edu, walmeida@microsoft.com
Cc: trintaeoitogc@gmail.com, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] checkpatch: throw error in malformed arrays
Date: Wed, 12 Feb 2025 16:48:57 -0300 [thread overview]
Message-ID: <20250212194857.192057-2-trintaeoitogc@gmail.com> (raw)
In-Reply-To: <20250212194857.192057-1-trintaeoitogc@gmail.com>
In module! macro, some fields have a string array type, and we need a
check for guarantee a good formatation.
Check if the current line contains one of these keys that must be a
string array and if so, make a regex for check if contains more than one
value in array, if yes, the array should be in vertical. If array have
only one value, so the array can be in the same line.
Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
---
scripts/checkpatch.pl | 68 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b28ad331742..d45536c2c63a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2775,6 +2775,9 @@ sub process {
$realcnt = 0;
$linenr = 0;
$fixlinenr = -1;
+
+ my %parse_module_arr;
+
foreach my $line (@lines) {
$linenr++;
$fixlinenr++;
@@ -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*\[/) {
+ $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;
+ }
+ }
+
+ 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));
+ }
+ 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:
+
+FROM
+'example': ['value',
+ 'value'
+
+TO
+'example': [
+ 'value',
+ 'value
+
+ ~);
+ }
+ elsif (!$inline && $line =~ /"\]/) {
+ ERROR("ERR_ARRAY_MODULE_MACRO",
+ qq~the key $key need a new line after last value and before ]\n$here\n~ . cat_vet($rawline) . qq~\nFor example:
+
+FROM
+'last_value']
+
+TO
+'last_value'
+]
+ ~);
+ }
+
+ #END OF ANALYZE FIELD
+ if ((!$inline || $line !~ $more_than_one_vl) && $line =~ /\]/) {
+ delete $parse_module_arr{author};
+ delete $parse_module_arr{alias};
+ delete $parse_module_arr{firmware};
+ }
+ }
+
+
#trailing whitespace
if ($line =~ /^\+.*\015/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
--
2.34.1
next prev parent reply other threads:[~2025-02-12 19:49 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 ` Guilherme Giacomo Simoes [this message]
2025-02-13 11:17 ` [PATCH 3/3] checkpatch: throw error in malformed arrays Joe Perches
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=20250212194857.192057-2-trintaeoitogc@gmail.com \
--to=trintaeoitogc@gmail.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=joe@perches.com \
--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=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;
as well as URLs for NNTP newsgroup(s).