Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2210232pxb; Sat, 21 Nov 2020 13:07:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4VIPMACEgFEu1w8gyCb0LOZkfqjziS3J18pE8lKsXqrGFIp3fBpaXO7m3XQNVv6a14V8+ X-Received: by 2002:a17:906:5617:: with SMTP id f23mr15624955ejq.352.1605992864241; Sat, 21 Nov 2020 13:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605992864; cv=none; d=google.com; s=arc-20160816; b=Jm4LCHDV12unKJF2yiPTSdmmgtDaWLB2Sed9qwrMjNHH5Yw2V/CfAepEDcKfzbIpZq 0TokXlKqGguRzgf5sUoRDE6oNZT7jwfRb5HYFYGZhgSjBuOUTO/C0utp+1B9ZScQfCa8 UvA+VPjKi/Tn9VIAYAp3LC5x7oniOMWOyN2aG+MRikueRjZ0NOS9d98ORmlFT68wEK4g dUf+QT0O+jzUjhdtxtG6duYOVBZMSXq7dCmr3XALPuzSA263OCN+aKnv7ccK8TAysRqu 0FqiKSBU9T5eyjSta2Tw7bHwAY9IXK3q5dAprr1boOaWNc4xGhzggj0jk7p49JdkskjB kSRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=GbxAeOvJk7Tb/1c/SoKJjtp//xhRkqyZpZjDLBwDuU8=; b=S2aNTGrBjBLU8wP/fWpaaFp1xHLck9caSpdQrLMUkiGtcp0Lrc8N0xBBKStAv4e5me G/8cx62+Ts2fvmGLFpRaS0YXOBBGuWxP9WmSl7urZOBHQmtTdFQzpSp5Jqm3SHhI3+WA nsGTfQABX7Ec1Lom25wsZ1heFN7pwmBNTl0lqMFFZidtmg/si8y0Wq9SlKfYmlj37McY Vaf8PG42OLx8NIk+BHa6ERqy3LVSPU77SUH/Y35rtymHnjgKI7tSDspT0TW12WwV7TQ7 pjoHmMF19Bt8PN0u7qEf508CTm6rA+xaHgPdedK4A8QDwkpZiMfMTpEq9yUwRjPUIwb7 5PLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="d/4PPvJn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si4057795eds.500.2020.11.21.13.07.20; Sat, 21 Nov 2020 13:07:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="d/4PPvJn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728513AbgKUVEy (ORCPT + 99 others); Sat, 21 Nov 2020 16:04:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgKUVEx (ORCPT ); Sat, 21 Nov 2020 16:04:53 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FBDAC0613CF for ; Sat, 21 Nov 2020 13:04:52 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id 10so11245098pfp.5 for ; Sat, 21 Nov 2020 13:04:52 -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=GbxAeOvJk7Tb/1c/SoKJjtp//xhRkqyZpZjDLBwDuU8=; b=d/4PPvJnTT35ihukdVwL1ye3WWxs6SkZzriQulEtZ1jdu8SwZPkCDXrCiej90IV2fk AmPb8dFqqWRfXLUlnHhG2+wC+HQEdhJJjtpS6oTZ7RDRHthu3Tf5AXxVlYTm8w9hfqyZ clLKl5+X9fentMD7xJX+ROtTgMij9kPihoiTGynETRBiI+KY60sFzBey6lL66Pk/l+NZ VbN5u+yg2ztSTP28Ae4haXaxJAfARSxaGSDkOHGwDPgLffosJaLvNJq1kp9pnsuY+w2i Cz6NmEVCT/M2sB3fH3M/P8ERnVjuQkZnWuHjfMNZvOrOsZDU5Y8Gd0MGEddQk1Kiii7A h39g== 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=GbxAeOvJk7Tb/1c/SoKJjtp//xhRkqyZpZjDLBwDuU8=; b=rCOJhk7RnkapOWVEHdrlcsDEabhxOV0rFgfcBrDy92i1y83G4avaLaw89tC09kdpl1 ycsC95+YXCQenEwK8zT+Js/ifGG/4iKoNV/8RiecAfFOQAKRx7jH0cW88uZcprq6M8Mx pEqwk36+HgNJbVzzXsUpUtfUg+Jk3jcuSFPDg4DeS31h78tgfjf8qeb2Kn7RsfND2cxD pMBu52GiA/HiqQguekoB63K7P9R96IhnqXlbghICO8zo3lgQIs+LaGJQup2OTd1fC5jL cao9fjnaoPlSUKt2dpFAb+16mCH1zryJJu8aFfpSrO0d9tPUG2kHM1lVRB08AyAY+Bu/ HPmg== X-Gm-Message-State: AOAM531e+i+wHWLJOdBC6nLNsjklLdqdWOE3IsSxZJ4KWSBaoBczE6se /Gq7eV3RJ3ZY2u4azEtTeNlFjicgHkX5Ug== X-Received: by 2002:a62:3381:0:b029:196:31a5:c2d4 with SMTP id z123-20020a6233810000b029019631a5c2d4mr19249675pfz.29.1605992691445; Sat, 21 Nov 2020 13:04:51 -0800 (PST) Received: from localhost.localdomain ([2402:3a80:43c:d362:ed91:20bf:333c:1bc4]) by smtp.googlemail.com with ESMTPSA id 84sm7817851pfu.53.2020.11.21.13.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 13:04:50 -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 v4] checkpatch: add fix option for LOGICAL_CONTINUATIONS Date: Sun, 22 Nov 2020 02:34:42 +0530 Message-Id: <20201121210442.17299-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 adding logical operator at the end of 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 scripts/checkpatch.pl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 5b1a5a65e69a..43a05519665d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3553,8 +3553,19 @@ 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 =~ /^\+/) { + # add logical operator to the previous line, remove from current line + # match line termination at comment or whitespace + if ($prevrawline =~ /(\s*(?:\/\/.*)*)$/) { + my $match = $1; + $fixed[$fixlinenr - 1] =~ s/$match//; + $fixed[$fixlinenr - 1] .= " $operator$match"; + } + $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//; + } } # check indentation starts on a tab stop -- 2.17.1