nicklockwood / SwiftFormat

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

unusedArguments stripping out used ones #1694

Closed victorBaro closed 1 month ago

victorBaro commented 1 month ago

When using new swift conditional variable unwrapping definition (i.e. let myOptional instead of let myOptional = myOptional), swiftFormat treats it as an unused argument.

Take the following code:

        listenForUpdates() { [weak self] update, error in
            guard let update, error == nil else {
                return
            }

            self?.configure(update)

        }

When using --stripunusedargs closure-only, it produces the following result, which results on a compiler error:

        listenForUpdates() { [weak self] _, error in // update variable gets replaced by _
            guard let update, error == nil else {
                return
            }

            self?.configure(update)

        }

Note that when using guard let update = update, swiftformat respects the variable and it does not replace it with _.

Tested with swiftformat v 0.53.8

nicklockwood commented 1 month ago

@victorBaro I suspect this is the same issue as https://github.com/nicklockwood/SwiftFormat/issues/1688, in which case it's already fixed, but I'll verify that before the next release

nicklockwood commented 1 month ago

@victorBaro fixed in 0.53.9