Redundant String Enum Value

String enum values can be omitted when they are equal to the enumcase name

  • Identifier: redundant_string_enum_value
  • Enabled by default: Yes
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

enum Numbers: String {
  case one
  case two
}
enum Numbers: Int {
  case one = 1
  case two = 2
}
enum Numbers: String {
  case one = "ONE"
  case two = "TWO"
}
enum Numbers: String {
  case one = "ONE"
  case two = "two"
}
enum Numbers: String {
  case one, two
}

Triggering Examples

enum Numbers: String {
  case one = "one"
  case two = "two"
}
enum Numbers: String {
  case one = "one", two = "two"
}
enum Numbers: String {
  case one, two = "two"
}