2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-02 15:25:22 +00:00

checkpatch: Omit some checks on comment lines.

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@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
This commit is contained in:
Ben Pfaff
2017-05-30 14:22:54 -07:00
parent 0b2c7e690a
commit d6ec6c108a

View File

@@ -85,6 +85,7 @@ __regex_is_for_if_single_line_bracket = \
__regex_ends_with_bracket = \ __regex_ends_with_bracket = \
re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$') re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$')
__regex_ptr_declaration_missing_whitespace = re.compile(r'[a-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_leading_whitespace_check = False
skip_trailing_whitespace_check = False skip_trailing_whitespace_check = False
@@ -187,6 +188,11 @@ def line_length_check(line):
return False 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 = [ checks = [
{'regex': None, {'regex': None,
'match_name': 'match_name':
@@ -204,14 +210,17 @@ checks = [
'print': lambda: print_warning("Line has trailing whitespace")}, 'print': lambda: print_warning("Line has trailing whitespace")},
{'regex': '(.c|.h)(.in)?$', 'match_name': None, {'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), 'check': lambda x: not if_and_for_whitespace_checks(x),
'print': lambda: print_error("Improper whitespace around control block")}, 'print': lambda: print_error("Improper whitespace around control block")},
{'regex': '(.c|.h)(.in)?$', 'match_name': None, {'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), 'check': lambda x: not if_and_for_end_with_bracket_check(x),
'print': lambda: print_error("Inappropriate bracing around statement")}, 'print': lambda: print_error("Inappropriate bracing around statement")},
{'regex': '(.c|.h)(.in)?$', 'match_name': None, {'regex': '(.c|.h)(.in)?$', 'match_name': None,
'prereq': lambda x: not is_comment_line(x),
'check': lambda x: pointer_whitespace_check(x), 'check': lambda x: pointer_whitespace_check(x),
'print': 'print':
lambda: print_error("Inappropriate spacing in pointer declaration")} lambda: print_error("Inappropriate spacing in pointer declaration")}
@@ -245,6 +254,7 @@ std_functions = [
checks += [ checks += [
{'regex': '(.c|.h)(.in)?$', {'regex': '(.c|.h)(.in)?$',
'match_name': None, 'match_name': None,
'prereq': lambda x: not is_comment_line(x),
'check': regex_function_factory(function_name), 'check': regex_function_factory(function_name),
'print': regex_error_factory(description)} 'print': regex_error_factory(description)}
for (function_name, description) in std_functions] for (function_name, description) in std_functions]
@@ -272,6 +282,8 @@ def run_checks(current_file, line, lineno):
global checking_file, total_line global checking_file, total_line
print_line = False print_line = False
for check in get_file_type_checks(current_file): for check in get_file_type_checks(current_file):
if 'prereq' in check and not check['prereq'](line):
continue
if check['check'](line): if check['check'](line):
check['print']() check['print']()
print_line = True print_line = True