2
0
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:
Ilya Maximets
2020-11-18 22:18:58 +01:00
parent a8ee6bf728
commit dc497e36fc
2 changed files with 30 additions and 0 deletions

View File

@@ -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),