nicklockwood / SwiftFormat

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

Unexpected token error since v0.49.15 #1253

Closed r-plus closed 2 years ago

r-plus commented 2 years ago

swift file

import UIKit

extension UIColor {
    var rgb: Int {
        var red: CGFloat = 0
        var green: CGFloat = 0
        var blue: CGFloat = 0
        var alpha: CGFloat = 0
        getRed(&red, green: &green, blue: &blue, alpha: &alpha)

        return lroundf(Float(red) * 255) << 16 | lroundf(Float(green) * 255) << 8 | lroundf(Float(blue) * 255)
    }
}

result

$ mint run swiftformat test.swift --swiftversion 5.6
🌱 Finding latest version of swiftformat
🌱 Running swiftformat 0.49.16...
Running SwiftFormat...
error: Unexpected token ) at 11:76 in /tmp/sw/test.swift.

v0.49.14 will not emit no error for this file.

raxityo commented 2 years ago

I also ran into this recently in v0.49.16. Workaround: Splitting the 3 colors into separate variables and performing the OR on those variables would make SwiftFormat happy.

nicklockwood commented 2 years ago

Thanks for the report - I actually found this yesterday and have already fixed it in the develop branch. I'll push a new release soon.

nicklockwood commented 2 years ago

Fixed in 0.49.17