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

Rule Request: Discourage Equality Checks Against RawValue #2146

Open
2 tasks done
Mazyod opened this issue Apr 5, 2018 · 0 comments
Open
2 tasks done

Rule Request: Discourage Equality Checks Against RawValue #2146

Mazyod opened this issue Apr 5, 2018 · 0 comments

Comments

@Mazyod
Copy link
Contributor

Mazyod commented Apr 5, 2018

New Issue Checklist

Rule Request

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.
    People are easily falling victims to equality check against rawValue, when it is much clearer/cleaner to check against the enum type.

  2. Provide several examples of what would and wouldn't trigger violations.

// trigger
switch string {
case MyEnum.caseA.rawValue:
  break
default:
  break
}

if value == MyEnum.caseA.rawValue {
  ...
}

// non-trigger
let possibleValue = MyEnum(rawValue: value)
if possibleValue == .caseA {
  ..
}

switch possibleValue {
case .some(.caseA):
  break
}
  1. Should the rule be configurable?
    Probably not?

  2. Should the rule be opt-in or enabled by default?
    Opt-in, for sure, since it is extremely disruptive to existing codebases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants