File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ func (w lintEmptyBlock) Visit(node ast.Node) ast.Visitor {
43
43
case * ast.SelectStmt :
44
44
w .ignore [n .Body ] = true
45
45
return w
46
+ case * ast.ForStmt :
47
+ if len (n .Body .List ) == 0 && n .Init == nil && n .Post == nil && n .Cond != nil {
48
+ if _ , isCall := n .Cond .(* ast.CallExpr ); isCall {
49
+ w .ignore [n .Body ] = true
50
+ return w
51
+ }
52
+ }
46
53
case * ast.RangeStmt :
47
54
if len (n .Body .List ) == 0 {
48
55
w .onFailure (lint.Failure {
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ type foo struct{}
11
11
func (f foo ) f (x * int ) {} // Must not match
12
12
func (f * foo ) g (y * int ) {} // Must not match
13
13
14
-
15
14
func h () {
16
15
go http .ListenAndServe ()
17
16
select {} // Must not match
@@ -43,6 +42,10 @@ func g(f func() bool) {
43
42
44
43
}
45
44
45
+ for true { // MATCH /this block is empty, you can remove it/
46
+
47
+ }
48
+
46
49
// issue 386, then overwritten by issue 416
47
50
var c = make (chan int )
48
51
for range c { // MATCH /this block is empty, you can remove it/
@@ -57,4 +60,34 @@ func g(f func() bool) {
57
60
if ok { // MATCH /this block is empty, you can remove it/
58
61
}
59
62
}
63
+
64
+ // issue 810
65
+ next := 0
66
+ iter := func (v * int ) bool {
67
+ * v = next
68
+ next ++
69
+ fmt .Println (* v )
70
+ return next < 10
71
+ }
72
+
73
+ z := 0
74
+ for iter (& z ) { // Must not match
75
+ }
76
+
77
+ for process () { // Must not match
78
+ }
79
+
80
+ var it iterator
81
+ for it .next () { // Must not match
82
+ }
83
+ }
84
+
85
+ func process () bool {
86
+ return false
87
+ }
88
+
89
+ type iterator struct {}
90
+
91
+ func (it * iterator ) next () bool {
92
+ return false
60
93
}
You can’t perform that action at this time.
0 commit comments