An object or the top level holds a public var, state that any code can change

tx0/kotlin:mutable-global-statestrictwarningmaintainability/designdepth fastsmell

What it finds

A public var in an object, a companion object or at the top level is one value shared by the whole program that any code can set, which makes behavior depend on the order of unrelated code and makes tests interfere with each other. Private state behind functions, or values passed in, keep changes in view.

From the rule's source, mutable_object_state.rs.

Example from the rule's tests
var counter = 0tx0 reports: counter is global state that any code can changeprivate var hidden = 0 object Settings {    var debug = falsetx0 reports: debug is global state    val name = "x"    var level = 1        private set} class Instance {    var value = 0}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:mutable-global-state" = "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:mutable-global-state] reason="..."

tx0 explain tx0/kotlin:mutable-global-state shows the same in the terminal. Found a false positive? Report it.