We’ve been encounter an issue where SonarQube rules keep scanning the SwiftUI and report this as a code smell but it is not. We currently just flag this as info level warning but it doesn’t help with the metrics.
Can anyone help or can we implement something to not scan this previews?? Thank you
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
FYI, this shows the preview layout during the Xcode development
I’m not familiar with Swift. Are the previews all collected in separate files, or scattered throughout regular code? If the former, you could set up an exclusion so those files aren’t analyzed - either at all or by specific rules.
It’s actually scattered throughout the code and it’s auto generated by Xcode. We also don’t want to exclude any files but we do want to stop scanning this. I tried //NOSONAR but that doesn’t seems working. From what I read on other topics that the Sonar team didn’t implement this for Swift language.
Thanks for the explanaton. I’m going to flag this for attention from the language experts. This may be something we want to handle more systematically.
Sorry for the long delay in answering this thread. As @RedDragonJ rightfully pointed out, ignoring issues in blocks is typically the feature one would need to skip specific code patterns, especially generated code.