nicklockwood / SwiftFormat

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

Disable `if let` and `guard let` shortened syntax in Swift 5.7 #1399

Closed bartlomiejswierad-vodeno closed 1 year ago

bartlomiejswierad-vodeno commented 1 year ago

Hey,

Currently, when I provide swift version 5.7, SwiftFormat enforces new shortened syntax of if let and guard let, when for some private reasons we can't use it. Is there a possibility to disable this rule?

Rule example: Before:

class Foo {
    var bar: String?

    func baz() {
        guard let bar = bar else { return }
        doAnything()
    }
    func doAnything() {}
}

After:

class Foo {
    var bar: String?

    func baz() {
        guard let bar else { return }
        doAnything()
    }
    func doAnything() {}
}

SwiftFormat: v0.51.2 Xcode 14.2 Swift 5.7.2 MacOS 13.2.1

nicklockwood commented 1 year ago

Yes, you can use --disable redundantOptionalBinding.

For future reference you can use --lint or --verbose to find out which rule was applied to which line so you know which to disable.

bartlomiejswierad-vodeno commented 1 year ago

Thanks for the advice!