diff mbox

[ovs-dev,3/3] checkpatch: Check for trailing operators.

Message ID 20170809203752.16886-3-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer Aug. 9, 2017, 8:37 p.m. UTC
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>
---
v2: Restrict to '?' and ':'.
    Make sure that goto tags aren't flagged.
---
 utilities/checkpatch.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Aug. 9, 2017, 8:59 p.m. UTC | #1
On Wed, Aug 09, 2017 at 01:37:52PM -0700, Joe Stringer wrote:
> 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>

The comment should be updated since the style considers && at the end of
a line to be OK:
> +    """Returns TRUE if the current line ends with an operator, eg &&"""

Otherwise:
Acked-by: Ben Pfaff <blp@ovn.org>
Joe Stringer Aug. 9, 2017, 11:58 p.m. UTC | #2
On 9 August 2017 at 13:59, Ben Pfaff <blp@ovn.org> wrote:
> On Wed, Aug 09, 2017 at 01:37:52PM -0700, Joe Stringer wrote:
>> 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>
>
> The comment should be updated since the style considers && at the end of
> a line to be OK:
>> +    """Returns TRUE if the current line ends with an operator, eg &&"""
>
> Otherwise:
> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks, I updated this comment and applied the patch to master.
diff mbox

Patch

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 1bb256ccd4d6..e553076d7d1c 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -94,6 +94,7 @@  __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_is_comment_line = re.compile(r'^\s*(/\*|\*\s)')
+__regex_trailing_operator = re.compile(r'^[^ ]* [^ ]*[?:]$')
 
 skip_leading_whitespace_check = False
 skip_trailing_whitespace_check = False
@@ -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 operator, eg &&"""
+    return __regex_trailing_operator.match(line) is not None
+
+
 checks = [
     {'regex': None,
      'match_name':
@@ -237,7 +243,13 @@  checks = [
      '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")},
 ]