nicklockwood / SwiftFormat

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

After redundantReturn is on, return is mistakenly deleted, resulting in a serious logical error. #1739

Open mlch911 opened 1 week ago

mlch911 commented 1 week ago
public func findNegativeFeedbackButton() -> NegativeFeedbackButton? {
    let btns = [topView, contentView, bottomView]
        .compactMap { $0 as? NegativeFeedbackCellProtocol }
        .map(\.negativeFeedbackButton)
    if btns.count > 1, let btn = btns.first { !$0.isHidden && $0.alpha > 0.01 } {
        return btn  // <== this return will be deleted...
    }
    return btns.first
}
nicklockwood commented 1 week ago

Sorry about that. The issue is due to the closure in the if statement condition causing the if statement body to be mistaken for a closure as well.

A workaround for now it to put parentheses around the { !$0.isHidden && $0.alpha > 0.01 }