diff --git a/rule/empty-block.go b/rule/empty-block.go index 8a4a0fef1..17652555f 100644 --- a/rule/empty-block.go +++ b/rule/empty-block.go @@ -40,6 +40,9 @@ func (w lintEmptyBlock) Visit(node ast.Node) ast.Visitor { case *ast.FuncLit: w.ignore[n.Body] = true return w + case *ast.SelectStmt: + w.ignore[n.Body] = true + return w case *ast.RangeStmt: if len(n.Body.List) == 0 { w.onFailure(lint.Failure{ diff --git a/testdata/empty-block.go b/testdata/empty-block.go index d75015757..ee257d001 100644 --- a/testdata/empty-block.go +++ b/testdata/empty-block.go @@ -2,6 +2,8 @@ package fixtures +import "net/http" + func f(x int) {} // Must not match type foo struct{} @@ -9,6 +11,12 @@ type foo struct{} func (f foo) f(x *int) {} // Must not match func (f *foo) g(y *int) {} // Must not match + +func h() { + go http.ListenAndServe() + select {} // Must not match +} + func g(f func() bool) { { // MATCH /this block is empty, you can remove it/ } @@ -44,4 +52,9 @@ func g(f func() bool) { for range s { // MATCH /this block is empty, you can remove it/ } + select { + case _, ok := <-c: + if ok { // MATCH /this block is empty, you can remove it/ + } + } }