=== compares identity with a literal, whose instances may or may not be shared

tx0/kotlin:identity-comparison-with-literalrecommendedwarningreliability/equalitydepth fastbug

What it finds

name === "admin" or count === 1000 asks whether two references are the same object. Strings and boxed numbers are shared only sometimes, by interning and caches, so the result depends on how the value was made. == compares the values.

From the rule's source, identity_on_literal.rs.

Example from the rule's tests
fun check(name: String, count: Int?, other: Any?) {    if (name === "admin") println("maybe")tx0 reports: === compares identity with the literal    if (count !== 1000) println("maybe")tx0 reports: !== compares identity with the literal 1000    if (other === null) println("fine")    if (name == "admin") println("fine")}
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:identity-comparison-with-literal" = "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:identity-comparison-with-literal] reason="..."

tx0 explain tx0/kotlin:identity-comparison-with-literal shows the same in the terminal. Found a false positive? Report it.