From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Andy Whitcroft <apw@shadowen.org>
Subject: [PATCH] checkpatch: Add test for comma use that should be semicolon
Date: Wed, 19 Aug 2020 14:22:10 -0700 [thread overview]
Message-ID: <3bf27caf462007dfa75647b040ab3191374a59de.camel@perches.com> (raw)
In-Reply-To: <20200818184107.f8af232fb58b17160c570874@linux-foundation.org>
There are commas used as statement terminations that should typically
have used semicolons instead. Only direct assignments or use of a single
function or value on a single line are detected by this test.
e.g.:
foo = bar(), /* typical use is semicolon not comma */
bar = baz();
Add an imperfect test to detect these comma uses.
No false positives were found in testing, but many types of false negatives
are possible.
e.g.:
foo = bar() + 1, /* comma use, but not direct assignment */
bar = baz();
Signed-off-by: Joe Perches <joe@perches.com
---
scripts/checkpatch.pl | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl=
index 60d4a79674b6..93b99809df07 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4936,6 +4936,17 @@ sub process {
}
}
+# check if a statement with a comma should be two statements like:
+# foo = bar(), /* comma should be semicolon */
+# bar = baz();
+ if (defined($stat) &&
+ $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) {
+ my $cnt = statement_rawlines($stat);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+ WARN("SUSPECT_COMMA_SEMICOLON",
+ "Possible comma where semicolon could be used\n" . $herectx);
+ }
+
# return is not a function
if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
my $spacing = $1;
next parent reply other threads:[~2020-08-19 21:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200818184107.f8af232fb58b17160c570874@linux-foundation.org>
2020-08-19 21:22 ` Joe Perches [this message]
2020-08-19 23:07 ` coccinelle: Convert comma to semicolons (was Re: [PATCH] checkpatch: Add test for comma use that should be semicolon) Joe Perches
2020-08-20 8:33 ` [Cocci] " Julia Lawall
2020-08-20 16:52 ` Joe Perches
2020-08-20 17:03 ` Julia Lawall
2020-08-20 17:28 ` Joe Perches
2020-08-22 1:08 ` Joe Perches
2020-08-22 3:35 ` Valdis Klētnieks
2020-08-22 5:30 ` Joe Perches
2020-08-22 7:07 ` Julia Lawall
2020-09-24 20:19 ` Thomas Gleixner
2020-09-24 20:21 ` Julia Lawall
2020-09-24 20:33 ` Joe Perches
2020-09-24 21:53 ` Thomas Gleixner
2020-09-24 22:23 ` Joe Perches
2020-09-25 17:06 ` Julia Lawall
2020-09-25 17:26 ` Joe Perches
2020-09-26 19:11 ` Valdis Klētnieks
2020-09-27 17:08 ` Julia Lawall
2020-09-27 17:45 ` Joe Perches
2020-09-27 19:35 ` Julia Lawall
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=3bf27caf462007dfa75647b040ab3191374a59de.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=apw@shadowen.org \
--cc=linux-kernel@vger.kernel.org \
/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).