Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3061013imb; Mon, 4 Mar 2019 23:14:19 -0800 (PST) X-Google-Smtp-Source: APXvYqz+g0ZYLCIRfFRiozM0nB2XqRmpHDQEOb+wTPMKX958ZMZVToPUtsBoNXSOSeNqZFLaR2RJ X-Received: by 2002:a63:c34a:: with SMTP id e10mr183519pgd.194.1551770059557; Mon, 04 Mar 2019 23:14:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551770059; cv=none; d=google.com; s=arc-20160816; b=hRzpUxvqAZ1gAzI/N2JCzR7rwkl1LzrYxShq2KrJYfu+P1nXAWAuvKL1rODtcMjh4g Nmov94xG6aU6gckjVPmIZgKB7pwMu/vs7+G+E95pM9htI8leHgJuHZU7ZPPEVH+HF6WS KmyjUei0InH+cf5l1EGCDT6flO5vQOrgOgtNPNFyhtGZvJMw2F3sakPOhd+Clu3nX5ll X1EduhSAj+fJAWfLhSnkS6S2kLoUELXVxf3OnR3ihrNlyRXI79g0E/GtpMc0GNINrIPd tLtEP0ViaEyyzAcRATOd45gHQMEYRqgz6N+36X4LwaOwsfmoab22etjETFGrhetbfzrp KLbw== 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 :message-id:date:subject:cc:to:from; bh=G/+gs4Ztzrtei5qpBK9NJ/P92fFz0YlKyWsuTL6oXAY=; b=nyeQusoCKfJ/ctym/8l/DfywV/0VIjYrCssHhqezj+7U9n9oGq0pKKM5rKisDZylml abUFnfShKPFFpfU07mimHoj9tAxFAxape9cXvlkNyC8mXyh4u11YcHGJmY5iuIZCd0cp BKQZLybuBZqn4gm7vup1wm5a8BnNAs821Izm0Az0D/Vk+xgN0A6syk4l5LbGQmnxRpgW XyVqS+JRha2sGFOz75duAuKjJe1D5APQ5ZRhcYofkQMwSXVhIJqb10NJUiBUqwkA42mF s+vYu0lICna9OpjPfbyCcRteok9wm9VG/qTaZF3UMn63ffFTAx+uBKQxhJ6aCtA6cyN8 4QQw== 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 75si7089343pgb.230.2019.03.04.23.14.04; Mon, 04 Mar 2019 23:14:19 -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 S1726660AbfCEHM4 (ORCPT + 99 others); Tue, 5 Mar 2019 02:12:56 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:50927 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfCEHM4 (ORCPT ); Tue, 5 Mar 2019 02:12:56 -0500 X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 63E5620002; Tue, 5 Mar 2019 07:12:53 +0000 (UTC) From: Alexandre Ghiti To: Andy Whitcroft , Joe Perches , linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v2] scripts: checkpatch: Check multiple blank lines when deleting code Date: Tue, 5 Mar 2019 02:12:51 -0500 Message-Id: <20190305071251.28427-1-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Alexandre Ghiti --- Changes in v2: - Fix the --fix option scripts/checkpatch.pl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b737ca9d7204..7dc12c137009 100755 --- 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); } 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) { 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; -- 2.20.1