Skip to content

if let from Swift 5.7 #4202

Description

@t8n

Suggestion to add a rule to help finding code that can be changed to use the short version of if let,

if let foo = foo {
  bar(foo)
}

to:

if let foo {
  bar(foo)
}

I've used this in my .yml which does the trick for my code, but I'm sure it can be improved to cover more cases:

  use_short_if_let:
    name: "Use short if let"
    regex: "if let (\\w*) = \\1(,| {)"
    capture_group: 0
    severity: warning

Metadata

Metadata

Assignees

Labels

rule-requestRequests for a new rules.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions