Here is a case where it thinks that the variable @State is not being used
struct ContentView: View {
@State var text = "" // SonarQube will give an warning + code smell here for not using this variable
var body: some View {
CustomText(text: $text)
}
}
I wonder if anyone has any solutions or SonarQube team may need implement some updates?
I cannot reproduce this warning about the text variable supposedly being unused with SonarQube 9.4. Would you mind telling me which SonarQube version you are using ?
The rule title is
“Fields and variables that are never updated should be constant”
Code Smell Minor; pitfall; Available Since May 30, 2019; SonarQube (Swift); Constant/issue: 2min
I just realize this was part if the SwiftUI preview code so we might just use the ignore block regex to ignore this part
Since this code is part of the SwiftUI preview code, ignoring this block with a regex sounds like the best action to take. However, I am still frustrated that I cannot reproduce this false positive. If you happen to experience other false positives with this rule again, feel free to open a new thread.