mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.74k stars 276 forks source link

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

Closed feldgendler closed 1 year ago

feldgendler commented 1 year ago

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:

chavacava commented 1 year ago

duplicated of #386

feldgendler commented 1 year ago

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?