From patchwork Fri Jul 14 20:59:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 788777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3x8Q6L5b7Rz9sBR for ; Sat, 15 Jul 2017 06:59:22 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 89145DD0; Fri, 14 Jul 2017 20:59:20 +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 8296ED75 for ; Fri, 14 Jul 2017 20:59:19 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E6B69453 for ; Fri, 14 Jul 2017 20:59:18 +0000 (UTC) Received: from mfilter10-d.gandi.net (mfilter10-d.gandi.net [217.70.178.139]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id B3D4F41C084 for ; Fri, 14 Jul 2017 22:59:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter10-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter10-d.gandi.net (mfilter10-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id ubu21ewhnURE for ; Fri, 14 Jul 2017 22:59:16 +0200 (CEST) X-Originating-IP: 208.91.1.34 Received: from carno.eng.vmware.com (unknown [208.91.1.34]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id BFF5741C08A for ; Fri, 14 Jul 2017 22:59:15 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Fri, 14 Jul 2017 13:59:06 -0700 Message-Id: <20170714205906.13268-1-joe@ovn.org> X-Mailer: git-send-email 2.11.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] [PATCH] checkpatch: Check for trailing operators. 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 style guide states that lines should not end with '&&', '||' '&' '|', '?', ':'. Check for this and report an error. Signed-off-by: Joe Stringer --- utilities/checkpatch.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 65d188d607f1..543762c22bd9 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -87,6 +87,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 @@ -199,6 +200,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': @@ -230,7 +236,12 @@ 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 operator at end of line")}, ]