SwiftFormat icon indicating copy to clipboard operation
SwiftFormat copied to clipboard

A parameter is incorrectly ignored

Open RussBaz opened this issue 1 year ago • 1 comments

The following snippet causes SwiftFormat to break the code:

func urlTestContains(path: String, strict _: Bool = true) -> Bool {
    let path = if path.hasSuffix("/") { path } else { "\(path)/" }

    return false
}

It does not detect that the path variable is used, and it will insert_ to the function signature.

I am sorry I could not describe the issue any better and could not verify if it was previously reported. Please have a look.

I am using swiftformat version 0.53.8.

Thank you.

RussBaz avatar Apr 26 '24 06:04 RussBaz

Should be fixed by https://github.com/nicklockwood/SwiftFormat/pull/1687

calda avatar Apr 28 '24 14:04 calda

@RussBaz fix landed in 0.53.9

nicklockwood avatar May 12 '24 20:05 nicklockwood

Hi again. It seems like this issue has resurfaced for me. I am using 0.54.3. Can you check this?

RussBaz avatar Aug 10 '24 16:08 RussBaz

I can't reproduce this issue with the func urlTestContains sample code above, can you share new sample code that demonstrates the problem?

calda avatar Aug 10 '24 16:08 calda

This seems to reproduce my problem:

enum Sample {
    func invite(lang: String, randomValue: Int) -> String {
        let flag: String? = if randomValue > 0 { "hello" } else { nil }

        let lang = if let flag { flag } else { lang }

        return lang
    }
}

lang will be incorrectly replaced with lang _ in the function signature.

RussBaz avatar Aug 10 '24 16:08 RussBaz

Thanks for the sample code, here's a fix: https://github.com/nicklockwood/SwiftFormat/pull/1815

calda avatar Aug 10 '24 17:08 calda