nicklockwood / SwiftFormat

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

Capture Lists and `--wrapcollections` #1646

Closed rehatkathuria closed 3 months ago

rehatkathuria commented 3 months ago

I have the following:

let closure = { @MainActor [foo = state.foo, baz = state.baz] send in ...

which, when formatting with --wrapcollections before-first gives me the following:

let closure = { @MainActor [
                    foo = state.foo,
                    baz = state.baz,
                ] send in

which in turn gives me the following error:

Expected 'weak', 'unowned', or no specifier in capture list

rehatkathuria commented 3 months ago

Looks like this was complaining about the trailing , comma generated by another rule

nicklockwood commented 3 months ago

The wrapCollections rule is not supposed to wrap capture lists, and trailingCommas shouldn't insert a comma into one either. SwiftFormat was confused by the @MainActor attribute and thought the capture list was an array literal. I'll get this fixed.

nicklockwood commented 3 months ago

@rehatkathuria fixed in 0.53.5