From patchwork Thu Aug 17 21:26:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 802915 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 3xYK686WQpz9t3B for ; Fri, 18 Aug 2017 07:26:40 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1CC429AF; Thu, 17 Aug 2017 21:26:39 +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 066CA97A for ; Thu, 17 Aug 2017 21:26:38 +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 E8418452 for ; Thu, 17 Aug 2017 21:26:36 +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 E1716C5A60; Thu, 17 Aug 2017 23:26:34 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Thu, 17 Aug 2017 14:26:27 -0700 Message-Id: <20170817212627.3378-1-joe@ovn.org> X-Mailer: git-send-email 2.14.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCHv2] 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, particularly for 'else' statements. Signed-off-by: Joe Stringer Acked-by: Aaron Conole --- v2: Combine in same check as if_and_for_end_with_bracket_check --- utilities/checkpatch.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 43f10bb3ded3..185ddaf0d5e9 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 @@ -186,6 +188,10 @@ def if_and_for_end_with_bracket_check(line): return True if __regex_ends_with_bracket.search(line) is None: return False + if __regex_conditional_else_bracing.match(line) is not None: + return False + if __regex_conditional_else_bracing2.match(line) is not None: + return False return True