ForgeCredoChecks.MapGetWithOr (forge_credo_checks v0.7.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Replace Map.get(map, key) || fallback with Map.get/3 or boundary normalization.

Why

Map.get/2 || fallback silently treats false as missing data and encourages call sites to fish through input shapes instead of defining one shape at the boundary. LLMs frequently produce this when they are unsure whether a value lives under one key, another key, or another map.

How to fix

# BEFORE
Map.get(opts, :retries) || 0

# AFTER
Map.get(opts, :retries, 0)

If the fallback is another source, normalize the input once at the ingestion boundary and read the normalized key locally.

What NOT to do

Do not chain Map.get/2 calls with || to support several possible input shapes. That hides schema drift and turns every consumer into a partial data-normalization layer.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.