nicklockwood / SwiftFormat

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

redundantReturn causes build failure #922

Closed calda closed 3 years ago

calda commented 3 years ago

In this example, the redundantReturn rule unexpectedly removed the return keyword in the catch block, which causes the build to fail.

Before

private func method() {
    let foo: String
    do {
        foo = try failableMethod()
    } catch Feature.error {
        print("Handled specific error")
        return
    } catch {
        print("Handled general error")
        return
    }

    print(foo)
}

After running swiftformat . --rules redundantReturn

This no longer compiles:

private func method() {
    let foo: String
    do {
        foo = try failableMethod()
    } catch Feature.error {
        print("Handled specific error")
    } catch {
        print("Handled general error")
        return
    }

    print(foo)
}
nicklockwood commented 3 years ago

@calda fixed in 0.48.1