A - or + expression on the line after an assignment is a statement of its own, and its value is dropped

tx0/kotlin:unary-operator-on-own-linerecommendedwarningreliability/logicdepth fastbug

What it finds

A line break ends a statement in Kotlin, so in

``kotlin val total = base - discount ``

- discount is a statement of its own and total is base. A binary operator other than ., ?., ?:, && and || has to end the line to continue the expression.

From the rule's source, discarded_unary.rs.

Example from the rule's tests
fun price(base: Int, discount: Int): Int {    val total = base        - discounttx0 reports: the value of - discount is dropped    val negative = -discount    val ok = !true    return total + negative}
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:unary-operator-on-own-line" = "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:unary-operator-on-own-line] reason="..."

tx0 explain tx0/kotlin:unary-operator-on-own-line shows the same in the terminal. Found a false positive? Report it.