1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-28 08:49:11 +02:00
revive/fixtures/empty-block.go
chavacava c9bde6c503 empty-block: ignore checking blocks of funcs and func literals (#17)
* Adds rule superfluous-else (an extension of indent-error-flow)

* Fix superfluous-else rule struct namming.

* Adds superfuous-else rule to the rules table

* Modifies empty-block rule to ignore bodies of
func literals and funcs

* add test cases on functions with a receiver for completeness
2018-06-11 12:08:58 -07:00

39 lines
731 B
Go

// Test of empty-blocks.
package fixtures
func f(x int) bool {} // Must not match
type foo struct {}
func (f foo) f(x *int) string {} // Must not match
func (f *foo) g(y *int) string {} // Must not match
func g(f func() bool) string {
{ // MATCH /this block is empty, you can remove it/
}
a := func(e error){} // Must not match
if ok := f(); ok { // MATCH /this block is empty, you can remove it/
// only a comment
} else {
println("it's NOT empty!")
}
if ok := f(); ok {
println("it's NOT empty!")
} else { // MATCH /this block is empty, you can remove it/
}
for i := 0; i < 10; i++ { // MATCH /this block is empty, you can remove it/
}
for { // MATCH /this block is empty, you can remove it/
}
}