[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250214184550.120775-3-trintaeoitogc@gmail.com>
Date: Fri, 14 Feb 2025 15:45:50 -0300
From: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
To: 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
Cc: trintaeoitogc@...il.com,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH V2 2/2] checkpatch: throw error in malformed arrays
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@...il.com>
---
scripts/checkpatch.pl | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b28ad331742..89fbec713bf3 100755
--- 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
+ my $inline = 0;
+ my $key = "";
+ my $add_line = $line =~ /^\+/;
+
+ if ($line =~ /\s*.*\b(author|alias|firmware)\s*:\s*\[/) {
+ $inline = 1;
+ $array_parse_module{$1} = 1;
+ }
+
+ my @keys = keys %array_parse_module;
+ if (@keys) {
+ $key = $keys[0];
+ }
+
+ if ($add_line && $key) {
+ my $herevet = "\n$here\n" . cat_vet($rawline) . "\n";
+
+ my $counter = () = $line =~ /"/g;
+ my $more_than_one = $counter > 2;
+ if ($more_than_one) {
+ WARN("ARRAY_MODULE_MACRO",
+ "Prefere one value per line$herevet");
+ } elsif ($inline && $line !~ /\]/ && $line !~ /,/ && $line =~ /"/) {
+ WARN("ARRAY_MODULE_MACRO",
+ "Prefere declare ] in the same line$herevet");
+ } elsif (!$inline && $line =~ /\]/ && $line =~ /\"/) {
+ WARN("ARRAY_MODULE_MACRO",
+ "Prefere a new line after last value and before ]$herevet");
+ } elsif ($inline && $line =~ /,/ && $line !~ /\]/) {
+ WARN("ARRAY_MODULE_MACRO",
+ "Prefere a new line after [$herevet");
+ }
+ }
+
+ #END OF ANALYZE FIELD
+ if ($line =~ /\]/) {
+ delete $array_parse_module{$key};
+ }
+
#trailing whitespace
if ($line =~ /^\+.*\015/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
--
2.34.1
Powered by blists - more mailing lists