filter { }.size builds a list only to count it, which count { } does without the list
What it finds
items.filter { it.done }.size makes a new list of the matching elements and throws it away after reading its size. items.count { it.done } counts in place.
From the rule's source, filter_then_size.rs.
fun done(items: List<Task>): Int { val a = items.filter { it.done }.sizetx0 reports: filter builds a list only to count it return a + items.count { it.done } + items.size} 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:
[rules]
"tx0/kotlin:filter-then-size" = "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:filter-then-size] reason="..."tx0 explain tx0/kotlin:filter-then-size shows the same in the terminal. Found a false positive? Report it.