From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7FB2C2D0E4 for ; Mon, 23 Nov 2020 10:28:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45D2B20888 for ; Mon, 23 Nov 2020 10:28:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mIR/WMKD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728220AbgKWK2b (ORCPT ); Mon, 23 Nov 2020 05:28:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727724AbgKWK2a (ORCPT ); Mon, 23 Nov 2020 05:28:30 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE28AC0613CF for ; Mon, 23 Nov 2020 02:28:30 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id 81so13868397pgf.0 for ; Mon, 23 Nov 2020 02:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qRhACkl7Rv1uiFh8nGeVLLx0hitLFn3xGhjC9ZYYm2s=; b=mIR/WMKDFuVlCPGZvcfujDdFLjDoYpA9VEarx8tSzci8KF76UTk9zJSaCd0/zXoKmm 7qPKRPk9ljIanB837jZ6mTRKugYuSSFpEGkV2PjPb66bgz6spS6uWXEhrnVwM/7aQ7pA kB9syVYMaA0uy/2FxAIUeRdNojRAmVCo9YRTmonu8VbcNIk+0yYMQ8OMMt6VSV7hMcOd 5JpFWZ6bXvfQMjeVb3LnBsVtX00+LcpTcDq12+vUmsC7DQN2hsVmSI2SmdH7tlNi0c67 AKE7xtwciWyPJl/A3Loj+0O/F+cBboH51Xo7xA06tbhSNewHh2hqPWO/zr48DnS46hzK a7qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qRhACkl7Rv1uiFh8nGeVLLx0hitLFn3xGhjC9ZYYm2s=; b=c4F6lKLHV9H4FExI5KYeKpN9c3em8Q1s5/39etVx9tVInIa8uU541Bh1tIG7G5wQbU f/UuqfQgXejJCtXA/HrcVClwjRDB+A0zJRpXD8Z13fG2jBInH6zy6TcrzFHvxyrcCjRy BhA5a7KcDD9UxJECN4CMAfze0Lfdlm/pMDPBDluQyDsiKGXh9yLNpj3vNTEQo5HviY89 I0jlPE6l6Wh/LoC4/4FuhdIXh96zMtshpr0CeUq2kTesUSW3m1QmYG07ybuABlkMfO/W gsvMAHvEpgthzqPlxhzodXEgZkIC2v6tyw53BwEnJtfR9xOsZkRlVMADjJykcEVfkz0z dQMw== X-Gm-Message-State: AOAM531ueltSOp7D9eGwxv41uYP8Iu8maMY9Y5543By3b6vYJysRxPRH I+0F6S9OLz1Q9BDvSPFQ77E= X-Google-Smtp-Source: ABdhPJyysChDwLc1e9sbiOMTb/IONSdknPwpSKenaAeO8j9mWeQXJWJ+8vzjQq2E0gRsbUGCVlnBaA== X-Received: by 2002:a17:90a:5e43:: with SMTP id u3mr23657809pji.216.1606127310005; Mon, 23 Nov 2020 02:28:30 -0800 (PST) Received: from localhost.localdomain ([2405:204:a68f:d31a:e4c8:22ff:b3cf:2a08]) by smtp.googlemail.com with ESMTPSA id o9sm14030919pjr.2.2020.11.23.02.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 02:28:29 -0800 (PST) From: Aditya Srivastava To: joe@perches.com Cc: yashsri421@gmail.com, lukas.bulwahn@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v7] checkpatch: add fix option for LOGICAL_CONTINUATIONS Date: Mon, 23 Nov 2020 15:58:18 +0530 Message-Id: <20201123102818.24364-1-yashsri421@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, checkpatch warns if logical continuations are placed at the start of a line and not at the end of previous line. E.g., running checkpatch on commit 3485507fc272 ("staging: bcm2835-camera: Reduce length of enum names") reports: CHECK:LOGICAL_CONTINUATIONS: Logical continuations should be on the previous line + if (!ret + && camera_port == Provide a simple fix by inserting logical operator at the last non-comment, non-whitespace char of the previous line and removing from current line, if both the lines are additions(ie start with '+') Signed-off-by: Aditya Srivastava --- changes in v2: quote $operator at substitution changes in v3: add a check for previous line ending with comment; If so, insert $operator at the last non-comment, non-whitespace char of the previous line changes in v4: improve the matching mechanism by matching line termination at comment or white space; insert the operator before comments (if any) separated by a whitespace; append the comment and its pre-whitespace after the inserted operator (if comment was present), ie if no comment was present nothing will be inserted after the operator changes in v5: improve regex for comment and line end with '$;' changes in v6: remove if-check; modify commit message changes in v7: add an extra '$' symbol at '$fixed[$fixlinenr - 1]' regex substitution to ensure match at line end scripts/checkpatch.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 5b1a5a65e69a..fb3c50e0bde2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3553,8 +3553,16 @@ sub process { # check for && or || at the start of a line if ($rawline =~ /^\+\s*(&&|\|\|)/) { - CHK("LOGICAL_CONTINUATIONS", - "Logical continuations should be on the previous line\n" . $hereprev); + my $operator = $1; + if (CHK("LOGICAL_CONTINUATIONS", + "Logical continuations should be on the previous line\n" . $hereprev) && + $fix && $prevrawline =~ /^\+/) { + # insert logical operator at last non-comment, non-whitepsace char on previous line + $prevline =~ /[\s$;]*$/; + my $line_end = substr($prevrawline, $-[0]); + $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/; + $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//; + } } # check indentation starts on a tab stop -- 2.17.1