realm / realm/SwiftLint

Rule Request: Discourage Equality Checks Against RawValue

Open
#2,146 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rule-request
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.