S1481 FP with Unused variable

  • Language: Kotlin
  • Rule: S1481
  • Why do you believe it’s a false-positive/false-negative? It is used just two lines below.
  • 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:
companion object {
  fun from(formula: String): MergeRule? {
    val lhs = formula.substringBefore('=').trim().ifEmpty { return null }
    val rhs = formula.substringAfter('=', "").trim()

    val ids = lhs.split(',').map { BenefitId(it.trim()) }.takeIf { it.size > 1 } ?: return null
    val merged = rhs.takeIf(String::isNotEmpty)?.let(::BenefitId)
    return MergeRule(ids.toSet() to merged)
  }
}