Credence.Pattern.NoMapPutGetIncrement (credence v0.7.1)

Copy Markdown

Detects Map.put(map, key, Map.get(map, key, 0) + 1) and rewrites to Map.update(map, key, 1, &(&1 + 1)).

Map.update/4 exists precisely for "update a value or insert a default" and avoids the redundant Map.get lookup. The +1 variant is by far the most common — it is the building block of manual frequency counting.

Bad

Map.put(counts, char, Map.get(counts, char, 0) + 1)

Good

Map.update(counts, char, 1, &(&1 + 1))

Auto-fix

Map.put(m, k, Map.get(m, k, 0) + 1)Map.update(m, k, 1, &(&1 + 1))