Re: [PATCH v3] scripts: checkpatch: Check multiple blank lines when deleting code

From: Alex Ghiti
Date: Mon Mar 25 2019 - 03:08:02 EST


On 3/17/19 11:49 AM, Alex Ghiti wrote:
On 3/6/19 2:53 PM, 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.

Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
---

Changes in v3 as suggested by Joe Perches:
ÂÂÂÂ- Do not try to fix this case
ÂÂÂÂ- Make this test separate from the insertion one so that warning
ÂÂÂÂÂ is more explicit

Changes in v2:
ÂÂÂÂ- Fix the --fix option

 scripts/checkpatch.pl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b737ca9d7204..c0728cff292f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3296,7 +3296,7 @@ sub process {
ÂÂÂÂÂÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂÂ }
 -# check for multiple consecutive blank lines
+# check for multiple consecutive blank lines caused by blank line insertion
ÂÂÂÂÂÂÂÂÂ if ($prevline =~ /^[\+ ]\s*$/ &&
ÂÂÂÂÂÂÂÂÂÂÂÂÂ $line =~ /^\+\s*$/ &&
ÂÂÂÂÂÂÂÂÂÂÂÂÂ $last_blank_line != ($linenr - 1)) {
@@ -3309,6 +3309,16 @@ sub process {
ÂÂÂÂÂÂÂÂÂÂÂÂÂ $last_blank_line = $linenr;
ÂÂÂÂÂÂÂÂÂ }
 +# check for multiple consecutive blank lines caused by code deletion
+ÂÂÂÂÂÂÂ if ($prevline =~ /^[\+ ]\s*$/ &&
+ÂÂÂÂÂÂÂÂÂÂÂ $line =~ /^ \s*$/ &&
+ÂÂÂÂÂÂÂÂÂÂÂ $last_blank_line != ($linenr - 1)) {
+ÂÂÂÂÂÂÂÂÂÂÂ CHK("LINE_SPACING",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "Avoid deleting lines that create consecutive blank lines\n" . $hereprev);
+
+ÂÂÂÂÂÂÂÂÂÂÂ $last_blank_line = $linenr;
+ÂÂÂÂÂÂÂ }
+
 # check for missing blank lines after declarations
ÂÂÂÂÂÂÂÂÂ if ($sline =~ /^\+\s+\S/ &&ÂÂÂÂÂÂÂÂÂÂÂ #Not at char 1
ÂÂÂÂÂÂÂÂÂÂÂÂÂ # actual declarations


Hi Joe,

Can I do something more this patch ?

Thanks,

Alex


Hi,

Sorry for insisting, but do you consider this patch for inclusion ?

Thanks,

Alex