diff mbox series

[RFC] scripts/checkpatch.pl:Add check for `while` and `for`

Message ID 1519480458-9573-1-git-send-email-suhang16@mails.ucas.ac.cn
State New
Headers show
Series [RFC] scripts/checkpatch.pl:Add check for `while` and `for` | expand

Commit Message

Su Hang Feb. 24, 2018, 1:54 p.m. UTC
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`.

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

no-reply@patchew.org Feb. 24, 2018, 7:20 p.m. UTC | #1
Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 1519480458-9573-1-git-send-email-suhang16@mails.ucas.ac.cn
Subject: [Qemu-devel] [PATCH RFC] scripts/checkpatch.pl:Add check for `while` and `for`

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
d557d98ca9 scripts/checkpatch.pl:Add check for `while` and `for`

=== OUTPUT BEGIN ===
Checking PATCH 1/1: scripts/checkpatch.pl:Add check for `while` and `for`...
ERROR: line over 90 characters
#32: FILE: scripts/checkpatch.pl:2356:
+		if ($line =~ /(^.*)\b(if|for|while)\b/ && $line !~ /\#\s*(if|for|while)/) {

total: 1 errors, 0 warnings, 8 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
diff mbox series

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1b4b812e28fa..cfe7e77d156f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2353,7 +2353,7 @@  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) {