Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unusedArguments does not work with switch-case-let #1901

Open
reika727 opened this issue Oct 6, 2024 · 0 comments
Open

unusedArguments does not work with switch-case-let #1901

reika727 opened this issue Oct 6, 2024 · 0 comments
Labels

Comments

@reika727
Copy link

reika727 commented Oct 6, 2024

I have a code like this:

enum TheEnum {
    case foo(Int)
}

func f(e: TheEnum, bar: String) {
    switch e {
    case let .foo(bar):
        print(bar)
    }
}

This code does not change after being formatted. However, the argument bar is not used inside the function f, so it should be func f(e: TheEnum, bar _: String) (since the unusedArguments option is enabled by default.) It seems that functions with switch-case-let are not formatted properly.

Just for your information, SwiftFormat works fine with functions with if-case-let or guard-case-let.

// BEFORE FORMATTED
enum TheEnum {
    case foo(Int)
}

func f(e: TheEnum, bar: String) {
    if case let .foo(bar) = e {
        print(bar)
    }
}

func g(e: TheEnum, bar: String) {
    guard case let .foo(bar) = e else { return }
    print(bar)
}
// AFTER FORMATTED
enum TheEnum {
    case foo(Int)
}

func f(e: TheEnum, bar _: String) {
    if case let .foo(bar) = e {
        print(bar)
    }
}

func g(e: TheEnum, bar _: String) {
    guard case let .foo(bar) = e else { return }
    print(bar)
}

Environment

$ swiftformat --version
0.54.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants