SonarQube Does Not Understand SwiftUI 2 Way Binding Symbol

SonarQube does not understand the new Two-way binding symbol in SwiftUI (Example: Two-way bindings in SwiftUI - a free SwiftUI by Example tutorial)

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?

Hello James,

Thank you for your feedback.

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 ?

Thank you,

We are using Enterprise Version 8.9.6

Still not able to reproduce it. Would you mind telling me which rule is raising this code smell?

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

Hello James,

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.


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