* [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl: add check for `while` and `for`
@ 2018-02-26 2:53 Su Hang
2018-02-27 17:32 ` Stefan Hajnoczi
0 siblings, 1 reply; 5+ messages in thread
From: Su Hang @ 2018-02-26 2:53 UTC (permalink / raw)
To: thuth, eblake, stefanha; +Cc: qemu-devel
Add check for `while` and `for` statements, which condition has more than
one line.
The former checkpatch.pl can check `if` statement, which condition has more
than one line, whether block misses brace round, like this:
'''
if (cond1 ||
cond2)
statement;
'''
But it doesn't do the same check for `for` and `while` statements.
Suggested-by: Eric Blake <eblake@redhat.com>
Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn>
---
scripts/checkpatch.pl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1b4b812e28fa..10c138344fa9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2353,7 +2353,8 @@ sub process {
}
# check for missing bracing round if etc
- if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+ if ($line =~ /(^.*)\b(for|while|if)\b/ &&
+ $line !~ /\#\s*(for|while|if)/) {
my ($level, $endln, @chunks) =
ctx_statement_full($linenr, $realcnt, 1);
if ($dbg_adv_apw) {
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl: add check for `while` and `for`
2018-02-26 2:53 [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl: add check for `while` and `for` Su Hang
@ 2018-02-27 17:32 ` Stefan Hajnoczi
2018-02-27 17:42 ` Peter Maydell
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2018-02-27 17:32 UTC (permalink / raw)
To: Su Hang; +Cc: thuth, eblake, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 744 bytes --]
On Mon, Feb 26, 2018 at 10:53:18AM +0800, Su Hang wrote:
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 1b4b812e28fa..10c138344fa9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2353,7 +2353,8 @@ sub process {
> }
>
> # check for missing bracing round if etc
Please fix the pre-existing typo in the comment:
s/round/around/
> - if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
> + if ($line =~ /(^.*)\b(for|while|if)\b/ &&
> + $line !~ /\#\s*(for|while|if)/) {
Please use (?:...) like most other cases in checkpatch.pl. Perl
automatically assigns groups to $1, $2, etc with (...). Using (?:...)
is preferred since it's faster and free of this side-effect.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl: add check for `while` and `for`
2018-02-27 17:32 ` Stefan Hajnoczi
@ 2018-02-27 17:42 ` Peter Maydell
2018-02-28 9:50 ` Stefan Hajnoczi
0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2018-02-27 17:42 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Su Hang, Thomas Huth, QEMU Developers
On 27 February 2018 at 17:32, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> On Mon, Feb 26, 2018 at 10:53:18AM +0800, Su Hang wrote:
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 1b4b812e28fa..10c138344fa9 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -2353,7 +2353,8 @@ sub process {
>> }
>>
>> # check for missing bracing round if etc
>
> Please fix the pre-existing typo in the comment:
>
> s/round/around/
That's not really a typo IMHO -- both 'round' and 'around'
seem fine to me here. (The OED entry for 'around' notes
"There is variation with 'round' adv. and prep. in many of the
senses below; in general 'around' is less usual in British usage",
so some of this is US-vs-UK usage or personal idiolect.)
thanks
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl: add check for `while` and `for`
2018-02-27 17:42 ` Peter Maydell
@ 2018-02-28 9:50 ` Stefan Hajnoczi
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2018-02-28 9:50 UTC (permalink / raw)
To: Peter Maydell; +Cc: Su Hang, Thomas Huth, QEMU Developers
[-- Attachment #1: Type: text/plain, Size: 1069 bytes --]
On Tue, Feb 27, 2018 at 05:42:50PM +0000, Peter Maydell wrote:
> On 27 February 2018 at 17:32, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> > On Mon, Feb 26, 2018 at 10:53:18AM +0800, Su Hang wrote:
> >> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> >> index 1b4b812e28fa..10c138344fa9 100755
> >> --- a/scripts/checkpatch.pl
> >> +++ b/scripts/checkpatch.pl
> >> @@ -2353,7 +2353,8 @@ sub process {
> >> }
> >>
> >> # check for missing bracing round if etc
> >
> > Please fix the pre-existing typo in the comment:
> >
> > s/round/around/
>
> That's not really a typo IMHO -- both 'round' and 'around'
> seem fine to me here. (The OED entry for 'around' notes
> "There is variation with 'round' adv. and prep. in many of the
> senses below; in general 'around' is less usual in British usage",
> so some of this is US-vs-UK usage or personal idiolect.)
Thanks! I hear British people use it frequently but thought it was a
colloquialism that isn't used in written form, innit? :) I stand
corrected.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl:Add check for `while` and `for`
2018-02-24 13:54 [Qemu-devel] [PATCH RFC] scripts/checkpatch.pl:Add " Su Hang
@ 2018-02-25 3:13 ` Su Hang
0 siblings, 0 replies; 5+ messages in thread
From: Su Hang @ 2018-02-25 3:13 UTC (permalink / raw)
To: thuth, eblake, stefanha; +Cc: qemu-devel
Add check for `while` and `for` statement, which condition has more than
one line.
The former checkpatch.pl can check `if` statement, which condition has more
than one line, whether block misses brace round, like this:
'''
if (cond1 ||
cond2)
statement;
'''
But it doesn't do the same check for `for` and `while` statement.
Suggested-by: Eric Blake <eblake@redhat.com>
Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn>
---
scripts/checkpatch.pl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1b4b812e28fa..7e332135e177 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2353,7 +2353,8 @@ sub process {
}
# check for missing bracing round if etc
- if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+ if ($line =~ /(^.*)\b(if|for|while)\b/ &&
+ $line !~ /\#\s*(if|for|while)/) {
my ($level, $endln, @chunks) =
ctx_statement_full($linenr, $realcnt, 1);
if ($dbg_adv_apw) {
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-02-28 9:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-26 2:53 [Qemu-devel] [PATCH v2 RFC] scripts/checkpatch.pl: add check for `while` and `for` Su Hang
2018-02-27 17:32 ` Stefan Hajnoczi
2018-02-27 17:42 ` Peter Maydell
2018-02-28 9:50 ` Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2018-02-24 13:54 [Qemu-devel] [PATCH RFC] scripts/checkpatch.pl:Add " Su Hang
2018-02-25 3:13 ` [Qemu-devel] [PATCH v2 " Su Hang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.