nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.63k stars 623 forks source link

`preferForLoop` picks `cas` identifier for `allCases` items #1631

Closed SimplyDanny closed 4 months ago

SimplyDanny commented 4 months ago

The example

enum E: CaseIterable { case a }

E.allCases.forEach {
    print($0)
}

is rewritten to

enum E: CaseIterable { case a }

for cas in E.allCases {
    print(cas)
}

which is valid. Yet, the chosen identifier cas comes a bit surprising. It's clear that identifier names can only be derived heuristically and case is a keyword in Swift that cannot be used. The allCases list is so common, though, that I suggest to use some real name instead like one of the defaults element, item or value. Other option: Use a quoted `case`.

nicklockwood commented 4 months ago

@SimplyDanny fixed in 0.53.3