Redundant String Enum Raw Value

ID

swift.redundant_string_enum

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Swift

Tags

code-smell, redundancy

Description

Reports a String-backed enum case whose explicit raw value equals the case name. The compiler already synthesises that mapping; spelling it out duplicates information.

enum Color: String {
    case red = "red"        // FLAW
    case green              // OK — implicit raw value
    case blue = "BLUE"      // OK — value differs from the name
}

Rationale

A reader has to look at both the case name and the raw value to verify they match. Removing the redundant value keeps the source short and guarantees the two stay in sync.

Remediation

Drop the redundant initializer:

enum Color: String {
    case red
    case green
    case blue
}