ExSlop.Check.Warning.DualKeyAccess (ExSlop v0.3.1)

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 normal and works with any version of Elixir.

Explanation

Checking both atom and string keys for the same field means the data shape is unknown. This is usually defensive coding where a boundary should normalize the map once.

# bad — doesn't know if keys are atoms or strings
Map.get(usage, :input_tokens) || Map.get(usage, "input_tokens") || 0
get_in(data, [:path]) || get_in(data, ["path"])
payload[:kind] || payload["kind"]

# good — normalize once at the boundary, then use one key type
Map.get(usage, :input_tokens, 0)

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.