[ovs-dev] [PATCH] checkpatch: Enforce bracing around conditionals.

Joe Stringer joe at ovn.org
Thu Aug 17 21:24:03 UTC 2017


On 17 August 2017 at 07:35, Aaron Conole <aconole at redhat.com> wrote:
> Hi Joe,
>
> Joe Stringer <joe at ovn.org> writes:
>
>> The coding style states that BSD-style brace placement should be used,
>> and even single statements should be enclosed. Add checks to checkpatch
>> for this.
>>
>> Signed-off-by: Joe Stringer <joe at ovn.org>
>> ---
>>  utilities/checkpatch.py | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
>> index 43f10bb3ded3..c8381c98403b 100755
>> --- a/utilities/checkpatch.py
>> +++ b/utilities/checkpatch.py
>> @@ -95,6 +95,8 @@ __regex_ends_with_bracket = \
>>  __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'^[^ ]* [^ ]*[?:]$')
>> +__regex_conditional_else_bracing = re.compile(r'^\s*else\s*{?$')
>> +__regex_conditional_else_bracing2 = re.compile(r'^\s*}\selse\s*$')
>>
>>  skip_leading_whitespace_check = False
>>  skip_trailing_whitespace_check = False
>> @@ -212,6 +214,12 @@ def trailing_operator(line):
>>      return __regex_trailing_operator.match(line) is not None
>>
>>
>> +def if_else_bracing_check(line):
>> +    if __regex_conditional_else_bracing.match(line) is not None:
>> +        return True
>> +    return __regex_conditional_else_bracing2.match(line) is not None
>> +
>> +
>
> Would it make more sense to put this in with the other bracing checks in
> if_and_for_end_with_bracket_check ?

Yes! Apparently I missed this before. Thanks, I'll respin.


More information about the dev mailing list