Rule Request: Discourage Equality Checks Against RawValue
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Rule Request
-
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 againstrawValue, when it is much clearer/cleaner to check against the enum type. -
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
}
-
Should the rule be configurable?
Probably not? -
Should the rule be opt-in or enabled by default?
Opt-in, for sure, since it is extremely disruptive to existing codebases.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the issue's Swift trigger and non-trigger examples and its requirement that the rule be opt-in. The work is complete when SwiftLint discourages the shown equality checks against enum rawValue while leaving the non-trigger examples unaffected; the issue names no implementation files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100