Credence.Pattern.NoEmptyMapNew (credence v0.7.1)

Copy Markdown

Detects Map.new() called with no arguments and suggests the empty map literal %{} instead.

Why this matters

Map.new() with zero arguments returns an empty map, identical to %{}. The literal %{} is the idiomatic Elixir way to express an empty map — it is shorter, more recognizable, and what every Elixir developer would reach for.

LLMs sometimes generate Map.new() because Map.new/1 and Map.new/2 are the idiomatic way to build a map from an enumerable. The zero-argument form is a misgeneralization of that pattern.

Flagged patterns

PatternSuggested replacement
Map.new()%{}

Only the zero-argument call is targeted. Map.new(enum), Map.new(enum, fun), and piped forms like enum |> Map.new() are all idiomatic and left alone.