Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3647848imb; Tue, 5 Mar 2019 15:18:10 -0800 (PST) X-Google-Smtp-Source: APXvYqx4BizRIb023sitm88Ngj60uLCnSpcLeLkc6b+ld/N7eVBSht5a9F9rEp5pTs12ItJR9AFc X-Received: by 2002:a62:1ac3:: with SMTP id a186mr4273042pfa.48.1551827890340; Tue, 05 Mar 2019 15:18:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551827890; cv=none; d=google.com; s=arc-20160816; b=P36qgt8sShDY2Qju6coKDmvWV/1QiFnXivH39v2463iTeP9wa4fqfZtQICmLGDiPMv fGHA42yL1YPqiT6dmAliUhRdFnnXzCCDTHDLC3qT2GRB+yHayCsXJz217MCjsJqgQk+Z WZAVMFR58UgjuKzXYm3N6zq4MQCffQisuX9UFzqiuj37epsA+hBkxYHtdA4LP0RiXoO+ ZSJuX5Z3MFm0bv+aK8cdY+JMiTIEhm0TkbBtljrIhnF4fnrz10PmI7NH0z1IsOIpg0lb QrvriJQbZ9agj2hNQTNm/Fs3Wmpim3MMMzRT7HzEFxfQkpRHPqRSHDe0o16SkPgtE9Ta gu8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:to:from:subject:message-id; bh=3eQ8+LNxfG70+cXHhAJkJp+ZLN4YGzNlogWIYwOp1WM=; b=rscDLJaJX1HVkzW8n3v0XFqNPSBwU2ZUuK9zy3OJSbbtleE2Du1upuEhVGOUKWSRgO 5IIQla7ES71AqCwqqIyt6bCwysf6vYsHvae6DFzFvtmaiO9K/swx5pkE6Q7mwet/clwJ SECRM4rT5bFO5i7q5HVlx9VYq61l1m3rSWVrdAxfRRzmKs1XSxl4KkwyLa/DljRw+UdD Cc47pWzdVV5Yc5BjphfDcu1J6//ZP1/qAtoUTwRu5BIoVmQ6kQV8Xoy9S9bVRtuLXXoI iQ9Yz/iRHFf6gqNjFLkmf+tWHeaGtKANelaXb9VD2yQPMlfBuu/1wSyLkyMl+PpO7p5N xmNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t80si20795pgb.69.2019.03.05.15.17.54; Tue, 05 Mar 2019 15:18:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727675AbfCEXRV (ORCPT + 99 others); Tue, 5 Mar 2019 18:17:21 -0500 Received: from smtprelay0020.hostedemail.com ([216.40.44.20]:43927 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726733AbfCEXRV (ORCPT ); Tue, 5 Mar 2019 18:17:21 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id 814F78368F17; Tue, 5 Mar 2019 23:17:19 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:599:982:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3653:3865:3867:3868:3871:3872:3874:4321:5007:7903:10004:10400:10848:11026:11232:11658:11914:12043:12438:12740:12760:12895:13095:13161:13229:13255:13439:14181:14659:14721:21063:21080:21433:21451:21611:21627:30012:30054:30070:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:29,LUA_SUMMARY:none X-HE-Tag: front84_7a10272ae8a18 X-Filterd-Recvd-Size: 2907 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf10.hostedemail.com (Postfix) with ESMTPA; Tue, 5 Mar 2019 23:17:18 +0000 (UTC) Message-ID: <266fda3bba4d9d73dd6268d2fd332c4bfb0ab4a2.camel@perches.com> Subject: Re: [PATCH v2] scripts: checkpatch: Check multiple blank lines when deleting code From: Joe Perches To: Alexandre Ghiti , Andy Whitcroft , linux-kernel@vger.kernel.org Date: Tue, 05 Mar 2019 15:17:17 -0800 In-Reply-To: <20190305071251.28427-1-alex@ghiti.fr> References: <20190305071251.28427-1-alex@ghiti.fr> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2019-03-05 at 02:12 -0500, Alexandre Ghiti wrote: > By matching only current line starting with '+', we miss the case > when deleting code makes consecutive blank lines appear: this patch > then makes it possible to detect this case by also matching current > line starting with ' ', which is an already existing blank line. [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -2081,10 +2081,15 @@ sub fix_inserted_deleted_lines { > } > > while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) { > + my $len = 1; > push(@lines, ${$inserted}{'LINE'}); > + # Do not increment the length when inserting a deletion line. > + if (${$inserted}{'LINE'} =~ /^\-/) { > + $len = 0; > + } > $inserted = @{$insertedRef}[$next_insert++]; > $new_linenr++; > - fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1); > + fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, $len); I think this is confusing and unnecessary. Using --fix can not delete context lines from a patch. > } > > if ($save_line) { > @@ -3298,12 +3303,18 @@ sub process { > > # check for multiple consecutive blank lines > if ($prevline =~ /^[\+ ]\s*$/ && > - $line =~ /^\+\s*$/ && > + $line =~ /^[\+ ]\s*$/ && > $last_blank_line != ($linenr - 1)) { > if (CHK("LINE_SPACING", > "Please don't use multiple blank lines\n" . $hereprev) && > $fix) { It's simpler to add a check that $line starts /^\+/ before $fix Maybe it'd be better to have a separate test for this to make the output message clearer too. Something like "Avoid deleting lines that create consecutive blank lines" > fix_delete_line($fixlinenr, $rawline); > + if ($line =~ /^ \s*$/) { > + # If the line is not an inserted blank line, the multiple > + # consecutive blank lines are caused by deletion: fix this > + # by replacing the blank line with a deletion line. > + fix_insert_line($fixlinenr, "\-"); > + } > } > > $last_blank_line = $linenr;