Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3882922imb; Tue, 5 Mar 2019 23:15:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzWP/KdLUwSz5YwvsNwK+LOxELICcIyPuIu1zQkNH4Gs2gacKnP1tYejK0awKvuVDHjpqFe X-Received: by 2002:a63:ce:: with SMTP id 197mr4977904pga.212.1551856501396; Tue, 05 Mar 2019 23:15:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551856501; cv=none; d=google.com; s=arc-20160816; b=VHCgeNov8MPNW5vnqguMUMl/hvaHROwJLsh0mkMPstdNOK3D/Z6jUEfrjT9aorq9E4 /PMM2I0YOY8oothC9HBt1lPxMvGV0kKw2WJIzCDaobzazQst07TDSNo3k5LxDBq0WxPD ExAtedsty4YBF57zgtLKan8gk36AodnmDjjSO0CMdDACaEeMRDZsRBp5N5J09NQ/uPcR bgGOb1HQH2sVOiMgrc/JlUnWtKl8A4GZFZzFYDpiOaD6U4qCsweGprEi3HjFRaDW1n4+ kP3qnGBx8/Y0Dx4UxPJH4I/+Ie5mO/itnh46u2q3POXa5Eja7Z3RQiTxf7XXw9XNwhcJ 1HYQ== 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:in-reply-to :mime-version:user-agent:date:message-id:references:subject:cc:to :from; bh=bZYRsj8eCC+jRdRUXHJlTa5ru06b++s8Dvf7nNZDv70=; b=UAv3DYDmmKwhCBiQw2Y+GSBOQEuF4cvBG3dnKSD6fig14eC1SAQ0ypWCqT0mAwqnW/ +liJsTCbgu72hFbQhZqQG7TUOXq+Lmg6EOdMK5cH+vrajXU/m8IsIGlqzxHvXyumLE0j fPlqS4oeyp4Sf5+2JHToy5N5bhfU6FxXyNpXLvpia7VTcKr2ucQna8T/FP15LQSu9x3m hJ1nB+bo4iZw9sl4TMn59L2sbSRYpK3Z2JrxApUMj7Fk4DCf5cJGU+F6y/RTkRq8G8Xb CODAn8dHpDdB9aJnoSi1KLzquWZOMovVy2eIoX8dnAius4CCgQP7UpmanGT9eJFLt/4k ukYw== 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 k18si963340pfj.46.2019.03.05.23.14.46; Tue, 05 Mar 2019 23:15:01 -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 S1729070AbfCFGt7 (ORCPT + 99 others); Wed, 6 Mar 2019 01:49:59 -0500 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:37925 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbfCFGt7 (ORCPT ); Wed, 6 Mar 2019 01:49:59 -0500 X-Originating-IP: 79.86.19.127 Received: from [192.168.0.11] (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id D9765240005; Wed, 6 Mar 2019 06:49:56 +0000 (UTC) From: Alex Ghiti To: Joe Perches Cc: Andy Whitcroft , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] scripts: checkpatch: Check multiple blank lines when deleting code References: <20190305071251.28427-1-alex@ghiti.fr> <266fda3bba4d9d73dd6268d2fd332c4bfb0ab4a2.camel@perches.com> Message-ID: <7ce1b638-7bc3-f82f-21ac-34519e698114@ghiti.fr> Date: Wed, 6 Mar 2019 01:49:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <266fda3bba4d9d73dd6268d2fd332c4bfb0ab4a2.camel@perches.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/5/19 6:17 PM, Joe Perches wrote: > 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. Ok, I was expecting your comment on that, I agree with you. So I'll get rid of the possibility to fix the deletion case, this will only be a warning. >> } >> >> 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" Ok, Thanks for your comments, >> 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;