Skip to content

enforce-switch-style: don't insist on default: when folowed by return #1541

@rtfb

Description

@rtfb

Is your feature request related to a problem? Please describe.
The rule complained about a code like this:

func isOneOf(what int) bool {
  switch what{
    case 1, 2, 3:
      return true
  }
  return false
}

While it obviously misses a default branch, it's also obviously equivalent to having one.

Describe the solution you'd like
I'd like to suggest to mute the "missing default branch" when the switch statement is followed by an immediate unconditional return. Having the default branch is not an end in itself, it's a means to having more robust code. And if the linter can trivially (or so it seems to my uneducated eye) check that the code is robust without complaining, it should not complain.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions