[ovs-dev] [PATCH] checkpatch: Omit some checks on comment lines.

Ben Pfaff blp at ovn.org
Tue May 30 21:22:54 UTC 2017


Comments are more freeform than code, so this patch tries to ignore many
checks on comment lines.  It assumes that any line that begins with "/*"
or "* " is a comment line.  (Without a following space, "*" might be
something like "*x = 1;".)

Suggested-by: Joe Stringer <joe at ovn.org>
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 utilities/checkpatch.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 751abd924c6a..083dbe6f682e 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -77,6 +77,7 @@ __regex_is_for_if_single_line_bracket = \
 __regex_ends_with_bracket = \
     re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$')
 __regex_ptr_declaration_missing_whitespace = re.compile(r'[a-zA-Z0-9]\*[^*]')
+__regex_is_comment_line = re.compile(r'^\s*(/\*|\*\s)')
 
 skip_leading_whitespace_check = False
 skip_trailing_whitespace_check = False
@@ -179,6 +180,11 @@ def line_length_check(line):
     return False
 
 
+def is_comment_line(line):
+    """Returns TRUE if the current line is part of a block comment."""
+    return __regex_is_comment_line.match(line) is not None
+
+
 checks = [
     {'regex': None,
      'match_name':
@@ -196,14 +202,17 @@ checks = [
      'print': lambda: print_warning("Line has trailing whitespace")},
 
     {'regex': '(.c|.h)(.in)?$', 'match_name': None,
+     'prereq': lambda x: not is_comment_line(x),
      'check': lambda x: not if_and_for_whitespace_checks(x),
      'print': lambda: print_error("Improper whitespace around control block")},
 
     {'regex': '(.c|.h)(.in)?$', 'match_name': None,
+     'prereq': lambda x: not is_comment_line(x),
      'check': lambda x: not if_and_for_end_with_bracket_check(x),
      'print': lambda: print_error("Inappropriate bracing around statement")},
 
     {'regex': '(.c|.h)(.in)?$', 'match_name': None,
+     'prereq': lambda x: not is_comment_line(x),
      'check': lambda x: pointer_whitespace_check(x),
      'print':
      lambda: print_error("Inappropriate spacing in pointer declaration")}
@@ -237,6 +246,7 @@ std_functions = [
 checks += [
     {'regex': '(.c|.h)(.in)?$',
      'match_name': None,
+     'prereq': lambda x: not is_comment_line(x),
      'check': regex_function_factory(function_name),
      'print': regex_error_factory(description)}
     for (function_name, description) in std_functions]
@@ -264,6 +274,8 @@ def run_checks(current_file, line, lineno):
     global checking_file, total_line
     print_line = False
     for check in get_file_type_checks(current_file):
+        if 'prereq' in check and not check['prereq'](line):
+            continue
         if check['check'](line):
             check['print']()
             print_line = True
-- 
2.10.2



More information about the dev mailing list