nonamedreturns
nonamedreturns copied to clipboard
[Good case] Handle errors in defer
I hate named returns too :)
Well, one case are good and should be allowed by linter I suppose.
func f() (retErr error) {
err := errors.New("foo")
defer func() {
if retErr == nil { // <-- analyse and replace returning error
retErr = errors.New("bar")
}
}()
return err
}
will leave this issue open until dependabot has picked it up on the golangci-lint
repo
TODO once v1.0.4 is merged into golangci-lint (job runs sunday):
- [ ] update option name in golangci-lint
- [ ] update tests in golangci-lint
Reference: https://github.com/golangci/golangci-lint/pull/2915
~Option is already added to golangci-lint (master branch)~
golangci/golangci-lint#2944