mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
checkpatch: Add check for a whitespace after cast.
Coding style says: "Put a space between the ``()`` used in a cast and the expression whose type is cast: ``(void *) 0``.". This style rule is frequently overlooked. Let's check for it. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: Ian Stokes <ian.stokes@intel.com>
This commit is contained in:
@@ -167,6 +167,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_cast_missing_whitespace = re.compile(r'\)[a-zA-Z0-9]')
|
||||
__regex_is_comment_line = re.compile(r'^\s*(/\*|\*\s)')
|
||||
__regex_has_comment = re.compile(r'.*(/\*|\*\s)')
|
||||
__regex_has_c99_comment = re.compile(r'.*//.*$')
|
||||
@@ -286,6 +287,12 @@ def pointer_whitespace_check(line):
|
||||
return __regex_ptr_declaration_missing_whitespace.search(line) is not None
|
||||
|
||||
|
||||
def cast_whitespace_check(line):
|
||||
"""Return TRUE if there is no space between the '()' used in a cast and
|
||||
the expression whose type is cast, i.e.: '(void *)foo'"""
|
||||
return __regex_cast_missing_whitespace.search(line) is not None
|
||||
|
||||
|
||||
def line_length_check(line):
|
||||
"""Return TRUE if the line length is too long"""
|
||||
if len(line) > 79:
|
||||
@@ -551,6 +558,12 @@ checks = [
|
||||
'print':
|
||||
lambda: print_error("Inappropriate spacing in pointer declaration")},
|
||||
|
||||
{'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None,
|
||||
'prereq': lambda x: not is_comment_line(x),
|
||||
'check': lambda x: cast_whitespace_check(x),
|
||||
'print':
|
||||
lambda: print_error("Inappropriate spacing around cast")},
|
||||
|
||||
{'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None,
|
||||
'prereq': lambda x: not is_comment_line(x),
|
||||
'check': lambda x: trailing_operator(x),
|
||||
|
Reference in New Issue
Block a user