Skip to content

Commit

Permalink
checkpatch: Check for trailing operators.
Browse files Browse the repository at this point in the history
The style guide states that lines should not end with '?' or ':'. Check
for this and report an error.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
joestringer committed Aug 9, 2017
1 parent bcd9335 commit 12f62e9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion utilities/checkpatch.py
Expand Up @@ -94,6 +94,7 @@ def reset_counters():
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)')
__regex_trailing_operator = re.compile(r'^[^ ]* [^ ]*[?:]$')

skip_leading_whitespace_check = False
skip_trailing_whitespace_check = False
Expand Down Expand Up @@ -206,6 +207,11 @@ def is_comment_line(line):
return __regex_is_comment_line.match(line) is not None


def trailing_operator(line):
"""Returns TRUE if the current line ends with an operatorsuch as ? or :"""
return __regex_trailing_operator.match(line) is not None


checks = [
{'regex': None,
'match_name':
Expand Down Expand Up @@ -237,7 +243,13 @@ def is_comment_line(line):
'prereq': lambda x: not is_comment_line(x),
'check': lambda x: pointer_whitespace_check(x),
'print':
lambda: print_error("Inappropriate spacing in pointer declaration")}
lambda: print_error("Inappropriate spacing in pointer declaration")},

{'regex': '(\.c|\.h)(\.in)?$', 'match_name': None,
'prereq': lambda x: not is_comment_line(x),
'check': lambda x: trailing_operator(x),
'print':
lambda: print_error("Line has '?' or ':' operator at end of line")},
]


Expand Down

0 comments on commit 12f62e9

Please sign in to comment.