1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-24 03:47:45 +02:00
revive/testdata/defer.go
Steven L db56db0b6a
Capture yet more bad defer / recover patterns (#719)
* Yet more bad defer / recover patterns

`recover()` is an eternal font of excitement.

* demonstrating another flavor of failure

* removing leftover code

* update documentation

* removes test not related to the rule itself

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-07-24 09:34:16 +02:00

36 lines
858 B
Go

package fixtures
import "errors"
type tt int
func (t tt) m() {}
func deferrer() {
for {
go func() {
defer println()
}()
defer func() {}() // MATCH /prefer not to defer inside loops/
}
defer tt.m() // MATCH /be careful when deferring calls to methods without pointer receiver/
defer func() error {
return errors.New("error") // MATCH /return in a defer function has no effect/
}()
defer recover() // MATCH /recover must be called inside a deferred function, this is executing recover immediately/
recover() // MATCH /recover must be called inside a deferred function/
defer deferrer()
helper := func(_ interface{}) {}
defer helper(recover()) // MATCH /recover must be called inside a deferred function, this is executing recover immediately/
// does not work, but not currently blocked.
defer helper(func() { recover() })
}