== on a BigDecimal treats 2.0 and 2.00 as different values
What it finds
BigDecimal.equals treats 2.0 and 2.00 as different numbers because their scales differ, so amount == BigDecimal.ZERO is false for an amount of 0.00. compareTo compares the values. Reported when one side is a BigDecimal constant or constructor call.
From the rule's source, decimal_equality.rs.
import java.math.BigDecimal fun free(amount: BigDecimal, price: BigDecimal): Boolean { if (amount == BigDecimal.ZERO) return truetx0 reports: BigDecimal equality also compares the scale if (price.equals(BigDecimal("1.50"))) return truetx0 reports: BigDecimal equality also compares the scale return amount.compareTo(BigDecimal.ZERO) == 0 || amount == price} 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:
[rules]
"tx0/kotlin:decimal-equality-with-scale" = "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:decimal-equality-with-scale] reason="..."tx0 explain tx0/kotlin:decimal-equality-with-scale shows the same in the terminal. Found a false positive? Report it.