SwiftFormat icon indicating copy to clipboard operation
SwiftFormat copied to clipboard

Rule `redundantSelf` shouldn't remove self for `@dynamicMemberLookup`

Open malaba opened this issue 3 years ago • 2 comments

What happens:

It appear that when the definition of the type with @dynamicMemberLookup isn't in the same file as an extension that use those member access, the mandatory self is removed by swiftformat.

Xcode project here.

The code compile, but once you run swiftformat at the root directory, it doesn't compile anymore.

Test on latest: Xcode v13.2.1, Swiftformat 0.49.4.

What is expected:

That swiftformat see that dynamic member lookup need self and it isn't removed.

Or if that is impossible (file parsed one by one without context from other files ?) then an option to specify some member lookup need the self (similar to --selfrequired for @ autoclosure).

malaba avatar Feb 15 '22 13:02 malaba

@malaba this is a known limitation of SwiftFormat's per-file formatting implementation. Currently no information is shared between files in a project, so it cannot know about a @dynamicMemberLookup declaration in another file. The only workaround for now is to use --selfrequired or disable the redundantSelf rule for that file.

nicklockwood avatar Feb 21 '22 10:02 nicklockwood

@nicklockwood Could --selfrequired perhaps accept type names in addition to function names?

domkm avatar Feb 27 '24 03:02 domkm