Skip to content

Configuration option to ignore error handling with early return linter #1253

@Jacobbrewer1

Description

@Jacobbrewer1

Is your feature request related to a problem? Please describe.

When using the early return option, it will pick up on the traditional Go error handling of

if err != nil {
    return err
}

Which then causes a pollution of

// nolint:revive // Traditional error handling

throughout the codebase.

Describe the solution you'd like

I would like to see an additional configuration argument come to the early return linter that allows for error handling statements to be excluded by the linter.

Describe alternatives you've considered

I have tried to add exclude statements to the rule to prevent this from returning an error, but this has had no success; additionally this is very restrictive and bound to a single handling of errors.

Config:

      - name: early-return
        severity: error
        disabled: false
        exclude: [ "if err != nil {" ]
        arguments:
          - "preserveScope"
          - "allowJump"

Output:

❯ golangci-lint run
client.go:106:2: early-return: if c { ... } can be rewritten if !c { return } ... to reduce nesting (revive)
        if err != nil {
                slog.Error("unable to renew auth info", slog.String(loggingKeyError, err.Error()))
                os.Exit(1)
        }

Additional context

N/a

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions