OeditusCredo.Check.Warning.UnsafeMapAccess
(OeditusCredo v0.6.0)
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
Using bracket access (map[:key]) on a map with atom keys silently
returns nil when the key is missing. The nil then propagates and
surfaces as a confusing error far from the source.
Prefer dot access, which raises a KeyError on missing keys and allows
Elixir 1.20's type system to propagate key requirements across call sites.
Bad:
config = %{timeout: 5000}
config[:timeout]Good:
config = %{timeout: 5000}
config.timeoutThis check requires the typle package and Elixir >= 1.20.
When either is unavailable, the check is silently skipped.
Check-Specific Parameters
Use the following parameters to configure this check:
:exclude_test_files
Set to true to skip test files (default: false)
This parameter defaults to nil.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.