S1128 FP with Redundant Import

  • Language: Kotlin
  • Rule: S1128
  • Why do you believe it’s a false-positive/false-negative? Code fails to compile if this suggestion is accpted.
  • Using:
    • SonarQube Enterprise Edition 9.9.4 (build 87374)
    • SonarLint 10.4.1.7799
      • IntelliJ Ultimate 2024.1 RC (Build #IU-241.14494.158)
      • in connected mode: yes, with SonarQube
  • Snippet:
import com.careem.subscription.mobile.components.Button as ButtonComponent
// ... com.careem.subscription.mobile.components.Text exists
import com.careem.subscription.mobile.text.Text as TextString

class SignupActionBarV2(
  val button: Button, // this is the button below
  val info: Info? = null,
  val actions: Actions,
) : BaseComponent(ComponentType("signupActionBarV2")) {

  // Kept for backward compatibility
  val action get() = (actions.onClick as? SignupActionOnClick)?.signupAction
  val event get() = (actions.onClick as? SignupActionOnClick)?.event

  class Info(
    val inline: SignupActionBarInline? = null,
    val footnote: Text? = null,
  )

  class Button(
    val label: TextString,
    val style: ButtonComponent.Style = ButtonComponent.Style.Primary,
  )
}

Hi,

Thanks for this detailed report!

I think you’re running into

SONARKT-366 FP in rule S1128 when import alias is from the same package

Unfortunately, I don’t have an ETA for this.

 
Ann

2 Likes