Credence.Pattern.NoEnumIntoEmptyMapset (credence v0.7.0)

Copy Markdown

Detects Enum.into/2 and Enum.into/3 targeting an empty MapSet.new() and suggests MapSet.new/1 or MapSet.new/2 instead.

Why this matters

Enum.into(enum, MapSet.new()) and Enum.into(enum, MapSet.new(), fun) are the generic collectable path for building MapSets. MapSet.new/1 and MapSet.new/2 exist specifically for this purpose, are more readable, and signal intent clearly.

LLMs frequently generate the Enum.into form because it is the general-purpose collector they learn from many examples. An Elixir developer would reach for MapSet.new by default.

Flagged patterns

PatternSuggested replacement
Enum.into(enum, MapSet.new())MapSet.new(enum)
Enum.into(enum, MapSet.new(), fun)MapSet.new(enum, fun)
`enum> Enum.into(MapSet.new())`MapSet.new(enum)
`enum> Enum.into(MapSet.new(), fun)`MapSet.new(enum, fun)

Only the bare MapSet.new() call with no arguments is targeted. Enum.into(enum, existing_mapset) where existing_mapset is not MapSet.new() is left alone — it merges into an existing MapSet, which MapSet.new does not do.