get(key) or set(key, value) is called by name where the index operator reads more naturally

tx0/kotlin:get-or-set-call-for-indexallwarningstyle/conventionsdepth faststyle

What it finds

map.get(key) and map.set(key, value) are what map[key] and map[key] = value mean. Receivers that look like reflection or references, such as a field or a ref, are left out, as their get is not an index.

From the rule's source, explicit_element_access.rs.

Example from the rule's tests
fun use(map: MutableMap<String, Int>, list: List<Int>, field: java.lang.reflect.Field, obj: Any) {    val a = map.get("a")tx0 reports: get reads more naturally as [key]    map.set("b", 2)tx0 reports: set reads more naturally as [key] = value    val b = list.get(0)tx0 reports: get reads more naturally    val c = field.get(obj)    val d = map["a"]}
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 all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:get-or-set-call-for-index" = "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:get-or-set-call-for-index] reason="..."

tx0 explain tx0/kotlin:get-or-set-call-for-index shows the same in the terminal. Found a false positive? Report it.