From patchwork Wed Aug 16 23:01:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 802273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xXlGC260gz9sN5 for ; Thu, 17 Aug 2017 09:01:39 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 81FBF8A5; Wed, 16 Aug 2017 23:01:36 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 2549D481 for ; Wed, 16 Aug 2017 23:01:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id F0147459 for ; Wed, 16 Aug 2017 23:01:34 +0000 (UTC) X-Originating-IP: 208.91.1.34 Received: from carno.eng.vmware.com (unknown [208.91.1.34]) (Authenticated sender: joe@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id E6B14C5A50 for ; Thu, 17 Aug 2017 01:01:32 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Wed, 16 Aug 2017 16:01:26 -0700 Message-Id: <20170816230126.29394-1-joe@ovn.org> X-Mailer: git-send-email 2.14.1 Subject: [ovs-dev] [PATCH] checkpatch: Enforce bracing around conditionals. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 --- 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 + + checks = [ {'regex': None, 'match_name': @@ -250,6 +258,11 @@ checks = [ 'check': lambda x: trailing_operator(x), 'print': lambda: print_error("Line has '?' or ':' operator at end of line")}, + + {'regex': '(.c|.h)(.in)?$', 'match_name': None, + 'prereq': lambda x: not is_comment_line(x), + 'check': lambda x: if_else_bracing_check(x), + 'print': lambda: print_error("Improper bracing in conditional statement")} ]