nicklockwood / SwiftFormat

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

[Request]: Add any to existentials in Swift 5.6+ mode #1193

Open jshier opened 2 years ago

jshier commented 2 years ago

It would be great if SwiftFormat could detect and update existential use to use the new any keyword introduced in Swift 5.6 (and required in Swift 6). I'm not sure whether you have in the info do that, but it would be good to get a head start on the feature.

func request(_ request: URLRequestConvertible)

would become

func request(_ request: any URLRequestConvertible)

where URLRequestConvertible is a protocol.

nicklockwood commented 2 years ago

This would require SwiftFormat to know which types are protocols, which it doesn't currently.

It could feasibly detect locally defined protocols within your project, and maybe have a list of known ones in Foundation, but there would still be gaps (e.g. ones defined in Objective-C, or 3rd party libs you've imported)