if (x != null) x else null gives back x in both cases

tx0/kotlin:null-check-returns-samerecommendedwarningmaintainability/complexitydepth fastsmell

What it finds

if (value != null) value else null and if (value == null) null else value are value: the check changes nothing about the result. Usually something else was meant in one branch.

From the rule's source, null_check_same_value.rs.

Example from the rule's tests
fun same(value: String?): String? {    val a = if (value != null) value else nulltx0 reports: the null check gives value either way    val b = if (value == null) null else valuetx0 reports: the null check gives value either way    val c = if (value != null) value.trim() else null    return a ?: b ?: c}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:null-check-returns-same" = "warning"

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:null-check-returns-same] reason="..."

tx0 explain tx0/kotlin:null-check-returns-same shows the same in the terminal. Found a false positive? Report it.