nicklockwood / SwiftFormat

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

redundantReturn removes return statements of consecutive if statements #1535

Closed antiraum closed 10 months ago

antiraum commented 10 months ago

I have a case where the redundantReturn rule falsely removes the return statements of consecutive if statements (swift version 5.9):

        Mirror(reflecting: self).children.compactMap { child -> String? in
            if
                let intValue = child.value as? Int,
                intValue == 0
            {
                return nil
            }
            if let label = child.label {
                return "\(label): \(child.value)"
            } else {
                return "\(child.value)"
            }
        }.joined(separator: ", ")

is transformed to

        Mirror(reflecting: self).children.compactMap { child -> String? in
            if
                let intValue = child.value as? Int,
                intValue == 0
            {
                nil
            }
            if let label = child.label {
                "\(label): \(child.value)"
            } else {
                "\(child.value)"
            }
        }.joined(separator: ", ")

which isn't valid.

nicklockwood commented 10 months ago

@antiraum thanks for reporting - I'll get it fixed asap

nicklockwood commented 10 months ago

@antiraum fixed in 0.52.6

calda commented 10 months ago

ahhh, thanks for the fix @nicklockwood!

antiraum commented 10 months ago

thanks for the quick fix