nicklockwood / SwiftFormat

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

Fix bug where if statement body could be incorrectly parsed as trailing closure #1719

Closed calda closed 3 weeks ago

calda commented 3 weeks ago

This PR fixes a bug where the body of an if statement could be incorrectly parsed as a trailing closure.

This fixes an issue where the redundantProperty rule would incorrectly convert this code:

func foo() -> Foo {
    let foo = Foo(bar: bar, baaz: baaz)

    if let foo = foo.nestedFoo {
        print(foo)
    }

    return foo
}

to:

func foo() -> Foo {
    let foo = Foo(bar: bar, baaz: baaz)

    if return foo.nestedFoo {
        print(foo)
    }
}
codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.16%. Comparing base (49330c8) to head (3b64a83).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1719 +/- ## =========================================== - Coverage 95.17% 95.16% -0.01% =========================================== Files 20 20 Lines 23177 23185 +8 =========================================== + Hits 22058 22065 +7 - Misses 1119 1120 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.