nicklockwood / SwiftFormat

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

Fix bug in `unusedArguments` when shadowing function argument with conditional assignment declaration #1687

Closed calda closed 2 months ago

calda commented 2 months ago

This PR fixes a bug in the unusedArguments rule when shadowing a function argument with a declaration where the value is an if or switch expression.

Before (argument unexpectedly marked as unused)

func test(foo _: Foo) {
    let foo =
        if foo.bar {
            baaz
        } else {
            bar
        }
    print(foo)
}

After (preserved)

func test(foo: Foo) {
    let foo =
        if foo.bar {
            baaz
        } else {
            bar
        }
    print(foo)
}
codecov[bot] commented 2 months ago

Codecov Report

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

Project coverage is 95.20%. Comparing base (3ed1b63) to head (fbd398e).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1687 +/- ## ======================================== Coverage 95.19% 95.20% ======================================== Files 21 21 Lines 23019 23023 +4 ======================================== + Hits 21913 21918 +5 + Misses 1106 1105 -1 ```

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