mirror of
https://github.com/mgechev/revive.git
synced 2025-04-17 11:46:37 +02:00
parent
251470be6a
commit
6a139caf92
@ -111,7 +111,7 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor {
|
|||||||
// but it is very likely to be a misunderstanding of defer's behavior around arguments.
|
// but it is very likely to be a misunderstanding of defer's behavior around arguments.
|
||||||
w.newFailure("recover must be called inside a deferred function, this is executing recover immediately", n, 1, "logic", "immediate-recover")
|
w.newFailure("recover must be called inside a deferred function, this is executing recover immediately", n, 1, "logic", "immediate-recover")
|
||||||
}
|
}
|
||||||
|
return nil // no need to analyze the arguments of the function call
|
||||||
case *ast.DeferStmt:
|
case *ast.DeferStmt:
|
||||||
if isIdent(n.Call.Fun, "recover") {
|
if isIdent(n.Call.Fun, "recover") {
|
||||||
// defer recover()
|
// defer recover()
|
||||||
|
17
testdata/defer.go
vendored
17
testdata/defer.go
vendored
@ -47,3 +47,20 @@ func f() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #1029
|
||||||
|
func verify2(a any) func() {
|
||||||
|
return func() {
|
||||||
|
fn := a.(func() error)
|
||||||
|
if err := fn(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainf() {
|
||||||
|
defer verify2(func() error { // MATCH /prefer not to defer chains of function calls/
|
||||||
|
return nil
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user