Skip to content

if-return incorrectly treated as golint rule #537

Closed
@rliebz

Description

@rliebz

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.

Because of this discrepancy, there is an increased barrier to adoption of revive over golint.

To Reproduce
Steps to reproduce the behavior:

  1. I updated revive go install github.com/mgechev/revive@latest
  2. 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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions