woshiccm / Pecker

CodePecker is a tool to detect unused Swift code.
MIT License
1.46k stars 63 forks source link

False Positive: SwiftUI Previews #26

Closed noahsark769 closed 4 years ago

noahsark769 commented 4 years ago

By default, SwiftUI generates a struct which conforms to PreviewProvider, e.g.:

import SwiftUI

struct SettingsView: View {
    var body: some View {
        ...
    }
}

#if DEBUG
struct SettingsView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsView()
    }
}
#endif

In the default configuration, pecker reports SettingsView_Previews as unused. It would be good to add a rule to ignore structs which conform to PreviewProvider.

woshiccm commented 4 years ago

Does static var previews also need to ignore?

woshiccm commented 4 years ago

Done, PR: https://github.com/woshiccm/Pecker/pull/28

noahsark769 commented 4 years ago

Thanks!