Repository: mgechev/revive (go)

Issue:
empty-lines false positive as of 1.2.2
Single line functions are flagged as having an erroneous newline at the start and end as of revive 1.2.2.

main.go:
```go
package main

func main() { println("foo") }
```

config.toml:
```toml
[rule.empty-lines]
```

```
@m4x3r:~/foo
$ go install github.com/mgechev/revive@v1.2.1

[19:54:35]
@m4x3r:~/foo
$ revive -config config.toml ./...

[19:54:39]
@m4x3r:~/foo
$ go install github.com/mgechev/revive@v1.2.2

[19:54:41]
@m4x3r:~/foo
$ revive -config config.toml ./...
main.go:3:13: extra empty line at the start of a block
main.go:3:13: extra empty line at the end of a block

[19:54:43]
@m4x3r:~/foo
$ go install github.com/mgechev/revive@v1.2.3

[19:54:46]
@m4x3r:~/foo
$ revive -config config.toml ./...
main.go:3:13: extra empty line at the start of a block
main.go:3:13: extra empty line at the end of a block
```

Pull request:
fix bug #739: empty-lines false positive
Closes #739 


Patch:
diff --git a/rule/empty-lines.go b/rule/empty-lines.go
index 1286607..2710a89 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


Test patch:
diff --git a/testdata/empty-lines.go b/testdata/empty-lines.go
index a37a778..916d69d 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") }