A val in an object or at the top level holds a literal and could be a const val
What it finds
A const val is inlined at compile time and can be used in annotations. A top-level or object val that is initialized with a number, boolean, character or string literal and has no getter, delegate or annotation can be one.
From the rule's source, could_be_const.rs.
val TIMEOUT = 30tx0 reports: TIMEOUT holds a literal and could be constconst val LIMIT = 10val label = "x"tx0 reports: label holds a literalval list = listOf(1)object Config { val PORT = 8080tx0 reports: PORT holds a literal @JvmField val HOST = "h"}class Holder { val size = 3} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:val-could-be-const" = "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:val-could-be-const] reason="..."tx0 explain tx0/kotlin:val-could-be-const shows the same in the terminal. Found a false positive? Report it.