?: null gives null when the value is already null

tx0/kotlin:elvis-returns-nullrecommendedwarningmaintainability/complexitydepth fastsmell

What it finds

value ?: null is value: the right side is used only when the left is null, and it is null too. The operator was likely meant to give a default.

From the rule's source, elvis_null.rs.

Example from the rule's tests
fun pick(value: String?, fallback: String?): String? {    val a = value ?: nulltx0 reports: value ?: null is the same as value    val b = value ?: fallback    return a ?: b}
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:elvis-returns-null" = "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:elvis-returns-null] reason="..."

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