Skip to contentSkip to conversation

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

RFC PATCH Superseded Su Hang 2 participants 3 messages Feb 24, 2018 – Feb 25, 2018 Checkpatch

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Su Hang

author
#0 lore raw

RFC PATCH 1/1 scripts/checkpatch.pl:Add check for `while` and `for`

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.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 1b4b812e28fa..cfe7e77d156f 100755
@@ -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) {
Signature · 1 line
2.7.4
author
#1 lore raw

RFC PATCH v2 1/1 scripts/checkpatch.pl:Add check for `while` and `for`

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.

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index 1b4b812e28fa..7e332135e177 100755
@@ -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) {
Signature · 1 line
2.7.4
#2 lore raw
In reply to Su Hang
This series seems to have some coding style problems. See output below for more information:

Hi,

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

Type: series
Message-id: [email protected]
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 [email protected]