Skip to content

Commit

Permalink
fix bug #739: empty-lines false positive (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava committed Aug 27, 2022
1 parent a4add4a commit 553604e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rule/empty-lines.go
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions testdata/empty-lines.go
Expand Up @@ -168,3 +168,6 @@ func ShouldNotWarn() {

// comment
}

// NR test for issue #739
func NotWarnInSingleLineFunction() { println("foo") }

0 comments on commit 553604e

Please sign in to comment.