From 553604eaced55ff3b0262525fa1cc19233cce297 Mon Sep 17 00:00:00 2001 From: chavacava Date: Sat, 27 Aug 2022 13:18:17 +0200 Subject: [PATCH] fix bug #739: empty-lines false positive (#742) --- rule/empty-lines.go | 4 ++-- testdata/empty-lines.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rule/empty-lines.go b/rule/empty-lines.go index 12866072e..2710a8979 100644 --- a/rule/empty-lines.go +++ b/rule/empty-lines.go @@ -51,7 +51,7 @@ func (w lintEmptyLines) checkStart(block *ast.BlockStmt) { firstNode := block.List[0] firstStmt := w.position(firstNode.Pos()) - firstBlockLineIsStmt := firstStmt.Line-(blockStart.Line+1) == 0 + firstBlockLineIsStmt := firstStmt.Line-(blockStart.Line+1) <= 0 _, firstBlockLineIsComment := w.cmap[blockStart.Line+1] if firstBlockLineIsStmt || firstBlockLineIsComment { return @@ -70,7 +70,7 @@ func (w lintEmptyLines) checkEnd(block *ast.BlockStmt) { lastNode := block.List[len(block.List)-1] lastStmt := w.position(lastNode.End()) - lastBlockLineIsStmt := (blockEnd.Line-1)-lastStmt.Line == 0 + lastBlockLineIsStmt := (blockEnd.Line-1)-lastStmt.Line <= 0 _, lastBlockLineIsComment := w.cmap[blockEnd.Line-1] if lastBlockLineIsStmt || lastBlockLineIsComment { return diff --git a/testdata/empty-lines.go b/testdata/empty-lines.go index a37a778db..916d69d14 100644 --- a/testdata/empty-lines.go +++ b/testdata/empty-lines.go @@ -168,3 +168,6 @@ func ShouldNotWarn() { // comment } + +// NR test for issue #739 +func NotWarnInSingleLineFunction() { println("foo") }