Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No defaults in enum switch #131

Open
matrinox opened this issue Sep 14, 2015 · 6 comments
Open

No defaults in enum switch #131

matrinox opened this issue Sep 14, 2015 · 6 comments
Labels
rule-request Requests for a new rules.

Comments

@matrinox
Copy link

I find the exhaustive enum warnings from the compiler super helpful. It ensures that whenever a new enum case is added, every switch statement is updated. But this won't work well with default. Often times the default is there as an easy way to group behaviour for the other cases at the time. I'd like to see this added as a warning

@jpsim jpsim added the rule-request Requests for a new rules. label Sep 19, 2015
@kevindelord
Copy link

+1 we also make sure to never use the default case in our enums :)

@Noobish1
Copy link

I'd love this feature also.

@jpsim
Copy link
Collaborator

jpsim commented Nov 21, 2015

I think this is a good rule to have, but it would be challenging to detect when the variable being switched on is an enum.

@acecilia
Copy link
Contributor

acecilia commented Jun 4, 2018

I would love to have this too :)

@valentinradu
Copy link

This would be great!

@sammy-SC
Copy link
Contributor

@jpsim

you mentioned that it would be challenging to detect when the variable being switched on is an enum.
In simple case like the one below, shouldn't it be sufficient to see whether the condition next to case is prepended with a dot? In this case .one? I think it should be safe to assume that variable being switched on is an enum if all conditions are prepended with a dot.

enum MyEnum {
  case one, two
}

let myEnum = MyEnum.two

switch myEnum {
  case .one: break
  default: break
}

Please let me know whether you think this could work, I would be happy to implement this rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests

7 participants