A when condition repeats an earlier one, so its branch never runs for that value
What it finds
when (code) { 1 -> a(); 2 -> b(); 1 -> c() }: the second 1 can never be chosen, as the first entry takes it. Usually one value was meant to be different. Conditions that call functions are left alone.
From the rule's source, duplicate_when_condition.rs.
fun describe(code: Int, x: Any): String = when (code) { 1 -> "one" 2, 3 -> "few" 1 -> "again"tx0 reports: the condition 1 repeats an earlier entry in 4..9 -> "some" else -> when (x) { is String -> "string" is String -> "twice"tx0 reports: the condition is String repeats else -> "other" }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/kotlin:duplicate-when-condition" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:duplicate-when-condition] reason="..."tx0 explain tx0/kotlin:duplicate-when-condition shows the same in the terminal. Found a false positive? Report it.