realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

unneeded_synthesized_initializer removes needed initializers if there is any other initializer enclosed within conditional macro #5574

Closed tristanSIF closed 1 month ago

tristanSIF commented 1 month ago

New Issue Checklist

Describe the bug

struct Foo {
    var bar: String

   // warning or removed according to unneeded_synthesized_initializer
    init(bar: String) {
        self.bar = bar
    }

    // or any other macros, such as canImport
    #if DEBUG  
    init(data: CGFloat) {
        self.bar = "\(data)"
    }
    #endif
}

/// compile error if autocorrect
let foo = Foo(bar: "bar")

Environment