From: Utkarsh Verma <utkarshverma294@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>,
linux-kernel@vger.kernel.org,
Utkarsh Verma <utkarshverma294@gmail.com>
Subject: [PATCH v3] checkpatch: add check for continue statement in UNNECESSARY_ELSE
Date: Sat, 2 Oct 2021 19:32:47 +0530 [thread overview]
Message-ID: <20211002140247.28677-1-utkarshverma294@gmail.com> (raw)
In-Reply-To: <d15bba541aac03ebe24c733f24b6bda96d03a3ec.camel@perches.com>
UNNECESSARY_ELSE only checks for the usage of else after a return or
break. But the same logic is also true for continue statement.
else used after a continue statement is unnecessary. So add a test
for continue statement also.
Signed-off-by: Utkarsh Verma <utkarshverma294@gmail.com>
---
scripts/checkpatch.pl | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c27d2312cfc3..0eee086d87fe 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4011,15 +4011,15 @@ sub process {
# check indentation of any line with a bare else
# (but not if it is a multiple line "if (foo) return bar; else return baz;")
-# if the previous line is a break or return and is indented 1 tab more...
+# if the previous line is a break or continue or return and is indented 1 tab more...
if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
my $tabs = length($1) + 1;
- if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ ||
- ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ &&
- defined $lines[$linenr] &&
- $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) {
+ if ($prevline =~ /^\+\t{$tabs,$tabs}(break|continue|return)\b/ &&
+ !($1 eq "return" &&
+ defined $lines[$linenr] &&
+ $lines[$linenr] =~ /^[ \+]\t{$tabs,$tabs}return/)) {
WARN("UNNECESSARY_ELSE",
- "else is not generally useful after a break or return\n" . $hereprev);
+ "else is not generally useful after a $1\n" . $hereprev);
}
}
--
2.25.1
next prev parent reply other threads:[~2021-10-02 14:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-25 20:17 [PATCH] Documentation: checkpatch: Document some more message types Utkarsh Verma
2021-09-27 17:43 ` Jonathan Corbet
2021-09-27 17:47 ` Utkarsh Verma
2021-09-27 17:53 ` Joe Perches
2021-10-01 12:02 ` [PATCH] docs: checkpatch: add UNNECESSARY_ELSE message Utkarsh Verma
2021-10-02 14:45 ` [PATCH v2] " Utkarsh Verma
2021-10-03 4:38 ` Dwaipayan Ray
2021-10-03 5:08 ` Lukas Bulwahn
2021-10-03 5:19 ` Utkarsh Verma
2021-10-03 5:31 ` Lukas Bulwahn
2021-10-03 5:23 ` Lukas Bulwahn
2021-10-01 19:09 ` [PATCH] Documentation: checkpatch: Document some more message types Utkarsh Verma
2021-10-01 19:26 ` [PATCH] checkpatch: add check for continue statement in UNNECESSARY_ELSE Utkarsh Verma
2021-10-01 20:22 ` Joe Perches
2021-10-01 20:47 ` [PATCH v2] " Utkarsh Verma
2021-10-01 21:09 ` Joe Perches
2021-10-02 14:02 ` Utkarsh Verma [this message]
2021-10-03 5:12 ` [PATCH v3] " Lukas Bulwahn
2021-09-29 5:28 ` [PATCH] Documentation: checkpatch: Document some more message types Lukas Bulwahn
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=20211002140247.28677-1-utkarshverma294@gmail.com \
--to=utkarshverma294@gmail.com \
--cc=apw@canonical.com \
--cc=dwaipayanray1@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.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).