[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <91569a87ac55da392fa894e8ad55292b98c558f3.camel@perches.com>
Date: Fri, 01 Oct 2021 13:22:13 -0700
From: Joe Perches <joe@...ches.com>
To: Utkarsh Verma <utkarshverma294@...il.com>,
Andy Whitcroft <apw@...onical.com>
Cc: Dwaipayan Ray <dwaipayanray1@...il.com>,
Lukas Bulwahn <lukas.bulwahn@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] checkpatch: add check for continue statement in
UNNECESSARY_ELSE
On Sat, 2021-10-02 at 00:56 +0530, Utkarsh Verma wrote:
> 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@...il.com>
> ---
> scripts/checkpatch.pl | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index c27d2312cfc3..f5a911aa6b64 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4011,15 +4011,16 @@ 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}continue\b/ ||
I suppose this is ok. I'd generally write this on one line.
if ($prevline =~ /^\+\t{$tabs,$tabs}(?:break|continue)\b/ ||
Powered by blists - more mailing lists