Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2151436pxb; Sat, 21 Nov 2020 10:36:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDQoiE+l7YdMgWAEmDR0qYY9w7ca275hbDfyXOYev6wEDTaF6+itqFXO+xHk00DA3K/Sli X-Received: by 2002:a05:6402:2373:: with SMTP id a19mr11964288eda.212.1605983800665; Sat, 21 Nov 2020 10:36:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605983800; cv=none; d=google.com; s=arc-20160816; b=AqUTkFveS8PpAP/Wlc0/6DoOvS/HBjysZsHYSmgc2KYJMinNV6SrTbk32f1ToC3peT JcTHAUCV2/MDi0TRpuDhukCJ/0NrbRyNxeQySMdv8kPUD8e08k8A9ha09XWfOVaPMP5H N61vQRkcXByLTAJjJqOeRjNpLih5Be8L4qDefO+qFtzC5jhdM7xGl9Fk3Owfi1adSPVY 5vzgogQ78pdflHiligzP+95n0JTOr2RcMAz84yNtea/ie+g1fcjFVc2mcx6mJXY/VRNr oy7EQkKriFkCjGkdkjLNQOOBZPSRk0kiqyH9EmZ9nCnqVnlidtV7sGPgL4K4gtEUNsGZ Nbkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=Uam8oK1UTeB5Xm2pnuEVQ+ceqFUhM0GAvcOg0oivdhc=; b=v3ZZLskNfWHOmkWgp5IHM2OXk8ll4H4TiXoc8JAm4wjBRNopB2xaWhKBo7YbxdoDfA 0htYFNUV76eZdaeOI6vsi5Gm7ysvouf86OYc4V8TvU9tE4BtNcFF/i/X3BQHHZdSGfMB DoxHPozPjNOJYien+bNL4wQsujVPdLljOi99I7uIBi0RA2kaPL1LDMbP7kpwWajNCdFc tIncZInHIwfSWQWL98VPwr1NT0irt3yMkoAjo7mkR+JM6XXNwTXVeMHJ+eu0MKGD4+b3 xJqNyCVlaNYfwAWoTPuL8QMMZHeX8MW119gKAmuhUtiT4x2lfd/8T2QvQBRULpFO6Jin TmMw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jx18si3731177ejb.601.2020.11.21.10.36.16; Sat, 21 Nov 2020 10:36:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728217AbgKUSef (ORCPT + 99 others); Sat, 21 Nov 2020 13:34:35 -0500 Received: from smtprelay0184.hostedemail.com ([216.40.44.184]:33740 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727228AbgKUSef (ORCPT ); Sat, 21 Nov 2020 13:34:35 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 1C9F4180A7FC6; Sat, 21 Nov 2020 18:34:34 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:800:960:968:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2197:2198:2199:2200:2201:2393:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3653:3865:3866:3867:3868:3870:3873:3874:4321:5007:7514:7903:9108:10004:10400:11232:11658:11914:12297:12438:12555:12740:12895:13069:13311:13357:13439:13894:14181:14659:14721:21080:21221:21451:21627:21740:21774:30030:30054:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: debt62_00182dd27356 X-Filterd-Recvd-Size: 2878 Received: from XPS-9350.home (unknown [47.151.128.180]) (Authenticated sender: joe@perches.com) by omf10.hostedemail.com (Postfix) with ESMTPA; Sat, 21 Nov 2020 18:34:33 +0000 (UTC) Message-ID: Subject: Re: [PATCH v3] checkpatch: add fix option for LOGICAL_CONTINUATIONS From: Joe Perches To: Aditya Srivastava Cc: lukas.bulwahn@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Date: Sat, 21 Nov 2020 10:34:31 -0800 In-Reply-To: <20201121181357.7621-1-yashsri421@gmail.com> References: <20201121181357.7621-1-yashsri421@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2020-11-21 at 23:43 +0530, Aditya Srivastava wrote: > 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 [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -3553,8 +3553,22 @@ 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 > + # if last line ends with a comment > + if ($prevrawline =~ /(\/\/.*)$/) { Not the best mechanism. check $prevline =~ /[\s$;]*$/ and use the starting position of any match as the insertion point, and then insert the operator and matching bits from the $prevrawline. I'll leave that as an exercise for you for now. > + my $comment = trim($1); > + $fixed[$fixlinenr - 1] =~ s/\s*$comment//; > + $fixed[$fixlinenr - 1] .= " $operator $comment";