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 for-range loop on a channel flagged by empty-block #861

Closed
feldgendler opened this issue Aug 9, 2023 · 2 comments
Closed

Empty for-range loop on a channel flagged by empty-block #861

feldgendler opened this issue Aug 9, 2023 · 2 comments

Comments

@feldgendler
Copy link

Describe the bug
An empty for ... range loop on a channel gets flagged by empty-block.

Unlike empty for ... range loops on slices and maps, one on a channel has an effect even when the body is empty: it drains the channel.

To Reproduce
revive@latest, no configuration file, all defaults, reports this code:

func drain(ch <-chan int) {
    for range ch {}
}

Expected behavior
empty-block is not triggered.

Logs

test.go:2:2: this block is empty, you can remove it

Desktop:

  • OS: Ubuntu 23.04
  • go version go1.20.6 linux/amd64
@chavacava
Copy link
Collaborator

duplicated of #386

@feldgendler
Copy link
Author

I can see that this is a duplicate of #386, whose fix was later reverted by #416. Do those reasons still stand? That was in 2020, and some things might have changed since (for instance, Go modules are now the norm).

I can see that many other revive checks use type information. Why can't this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants