Closed
Description
Describe the bug
The README describes if-return
as a golint
rule, and therefore includes it in the set of defaults here and in golangci-lint
. This is no longer true as of 2018.
- Related issue: Consider relaxing redundant assignment if it is part of a sequence golang/lint#363
- Related PR: golint: Removed redundant if ...; err != nil check golang/lint#388
Because of this discrepancy, there is an increased barrier to adoption of revive
over golint
.
To Reproduce
Steps to reproduce the behavior:
- I updated revive
go install github.com/mgechev/revive@latest
- I ran revive on the following file with no
config.toml
:
package example
import "errors"
// Foo ...
func Foo() error {
if err := returnErr(); err != nil {
return err
}
return nil
}
func returnErr() error {
return errors.New("oh no")
}
And got the following results:
$ revive example.go
example.go:7:2: redundant if ...; err != nil check, just return error instead.
With golint
:
$ golint example.go
# no output
Expected behavior
I would expect the output from revive
to be the same as golint
, since this is what the README claims.
Logs
N/A
Desktop (please complete the following information):
- OS: macOS 11.4
- Version of Go:
go version go1.16.5 darwin/amd64
Additional context
The same problem exists with golangci-lint
:
$ golangci-lint run -E revive .
example.go:7:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
if err := returnErr(); err != nil {
return err
}
$ golangci-lint run -E golint .
WARN [runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive.