A public property holds a mutable collection, so callers can change it behind the class's back

tx0/kotlin:public-mutable-collectionstrictwarningmaintainability/designdepth fastsmell

What it finds

val items = mutableListOf<Item>() in a public API hands every caller the right to add and remove items. A private mutable property with a read-only List view keeps changes inside the class.

From the rule's source, exposed_mutable_collection.rs.

Example from the rule's tests
class Cart {    val items = mutableListOf<String>()tx0 reports: the public items lets callers change the collection    val prices: MutableMap<String, Int> = HashMap()tx0 reports: the public prices lets callers    private val hidden = mutableListOf<String>()    val view: List<String> = hidden}
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:public-mutable-collection" = "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:public-mutable-collection] reason="..."

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