[ovs-dev] [PATCH v2 6/7] checkpatch: fix the if and whitespace checks

Aaron Conole aconole at bytheb.org
Fri Oct 21 18:49:08 UTC 2016


The regex for the if/for/while bracket tests fails to distinguish
non-space text.  This means text such as do_something_if() would match
incorrectly.

Additionally, the ends-with-bracket test doesn't allow for the common
coding paradigm:

    if (condition) { /* Text about conditional. */
    }

So fix that as well.

Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
 utilities/checkpatch.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index d21574c..ab389ba 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -59,13 +59,14 @@ __regex_leading_with_whitespace_at_all = re.compile(r'^\s+')
 __regex_leading_with_spaces = re.compile(r'^ +[\S]+')
 __regex_trailing_whitespace = re.compile(r'[^\S]+$')
 __regex_single_line_feed = re.compile(r'^\f$')
-__regex_for_if_missing_whitespace = re.compile(r'(if|for|while)[\(]')
-__regex_for_if_too_much_whitespace = re.compile(r'(if|for|while)  +[\(]')
-__regex_for_if_parens_whitespace = re.compile(r'(if|for|while) \( +[\s\S]+\)')
+__regex_for_if_missing_whitespace = re.compile(r' +(if|for|while)[\(]')
+__regex_for_if_too_much_whitespace = re.compile(r' +(if|for|while)  +[\(]')
+__regex_for_if_parens_whitespace = \
+    re.compile(r' +(if|for|while) \( +[\s\S]+\)')
 __regex_is_for_if_single_line_bracket = \
     re.compile(r'^ +(if|for|while) \(.*\)')
-
-__regex_ends_with_bracket = re.compile(r'[^\s]\) {$')
+__regex_ends_with_bracket = \
+    re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$')
 
 skip_leading_whitespace_check = False
 skip_trailing_whitespace_check = False
-- 
2.7.4




More information about the dev mailing list