2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

checkpatch: Check for infix operator whitespace.

The 'Expressions' section of the coding style specifies that one space
should be on either side of infix binary and ternary operators. This
adds a check to checkpatch.py for most of these.

The regex won't match if there are speech marks on the line, because
the style should not apply to the contents of strings.

This check is left at warning level because there isn't a good way to
determine whether a line is within a multiline comment or string, so it
will occasionally flag such lines which contain hyphenated words.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Joe Stringer
2017-08-09 13:37:50 -07:00
parent 13ad61c46e
commit 0d7b16daea

View File

@@ -275,6 +275,25 @@ checks += [
for (function_name, description) in std_functions]
def regex_operator_factory(operator):
regex = re.compile(r'^[^#][^"\']*[^ "]%s[^ "\'][^"]*' % operator)
return lambda x: regex.search(x) is not None
infix_operators = \
[re.escape(op) for op in ['/', '%', '<<', '>>', '<=', '>=', '==', '!=',
'^', '|', '&&', '||', '?:', '=', '+=', '-=', '*=', '/=', '%=',
'&=', '^=', '|=', '<<=', '>>=']] \
+ ['[^<" ]<[^=" ]', '[^->" ]>[^=" ]', '[^ !()/"]\*[^/]', '[^ !&()"]&',
'[^" +(]\+[^"+;]', '[^" -(]-[^"->;]', '[^" <>=!^|+\-*/%&]=[^"=]']
checks += [
{'regex': '(\.c|\.h)(\.in)?$', 'match_name': None,
'prereq': lambda x: not is_comment_line(x),
'check': regex_operator_factory(operator),
'print': lambda: print_warning("Line lacks whitespace around operator")}
for operator in infix_operators]
def get_file_type_checks(filename):
"""Returns the list of checks for a file based on matching the filename
against regex."""