Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty-block: Fix false positive on select {} #805

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rule/empty-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
13 changes: 13 additions & 0 deletions testdata/empty-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

package fixtures

import "net/http"

func f(x int) {} // Must not match

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/
}
Expand Down Expand Up @@ -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/
}
}
}