False Positive for swift:S1996 There are 2 independent types in this file in SwiftUI View files

Hello all,

Using Sonarqube Enterprise Edition Version 9.9 (build 65466), I’ve run into false positives in my SwiftUI View SonarQube reporting where files with a View struct and a View_Previews struct are showing up as multiple independent types in the same file violations. Can the rule ignore structs with a _Previews suffix?


//
//  ExampleView.swift
//
//  Created by Johnston, A on 8/15/23.
//

import SwiftUI

struct ExampleView: View {
    var body: some View {
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
    }
}

struct ExampleView_Previews: PreviewProvider {
    static var previews: some View {
        ExampleView()
    }
}

Much obliged!

hello @ajohnston ,

sorry for the late reaction. I believe you are correct and the rule should ignore such cases. I created the ticket to fix it https://sonarsource.atlassian.net/browse/SONARSWIFT-545

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.