Skip to content

empty-block false positive #1622

@scop

Description

@scop

Describe the bug

Revive can flag a false empty-block positive where the block contents is irrelevant, but there's important functionality going on in the for loop controls for the block.

To Reproduce

cat <<EOF >main.go
package main

var count int

func step() (int, bool) {
	// This could have all kinds of functionality.
	count++
	return count, count < 5
}

func main() {
	for _, c := step(); c; _, c = step() {
		// Here, the loop body is not important, the control using step() is.
	}
}
EOF
$ docker run -v "$(pwd)":/work ghcr.io/mgechev/revive:v1.13.0  ./work/main.go | grep empty
./work/main.go:12:39: this block is empty, you can remove it

Expected behavior

No empty-block flagged.

Logs
N/A

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu 18.04]
  • Version of Go

Using official revive Docker image.

Additional context
N/A

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions