S1128 FP with 'by' and 'collectAsState()'

  • What language is this for? Kotlin
  • Which rule? S1128
  • Why do you believe it’s a false-positive/false-negative? The import of androidx.compose.runtime.getValue is identified as unused by sonarlint but it is not. It is needed if collectAsState is used with by operator instead of using direct assignment of collectAsState().value where it is indeed not needed
  • Are you using
    • SonarCloud?
    • SonarQube - which version?
    • SonarLint - which IDE/version? ANDROID STUDIO FLAMINGO 2022.2.1, SonarLint SonarSource 8.1.0.65508
      • in connected mode with SonarQube or SonarCloud? NO
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import kotlinx.coroutines.flow.StateFlow

@Composable
fun testFP(someFlow : StateFlow<Int>) {
    val state by someFlow.collectAsState()

    //TODO use state
}

Hi @KlitosG ,

Thanks for the report. There is good news for you, [this problem has been resolved] recently([SONARKT-307] - Jira).

So you should see the change soon in the next update of SonarLint for Intellij or you can see it today if you use SonarLint in connected mode with SonarCloud.

Cheers,

Dorian

Thanks Dorian,

It’s not a big deal for me, happy that it is fixed, I will wait for the next update

1 Like

I am now in version 10.0.1.77000 of SonarLint and this false positive still persists.
Can you please let me know what version this is fixed on?

Cheers,
Klitos