LexCredo.Check.Warning.NoEnumAllAssert (LexCredo v0.1.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 normal and works with any version of Elixir.

Explanation

Avoid assert Enum.all?/2 in test files. Use for with individual assertions instead.

assert Enum.all?(collection, predicate) only tells you that at least one element failed. A for loop with individual assert calls pinpoints the exact failing element, making failures much easier to diagnose.

# BAD — only tells you something failed, not which element
assert Enum.all?(posts, &match?(%Post{}, &1))

# GOOD — reports exactly which element failed
for post <- posts, do: assert %Post{} = post

Check-Specific Parameters

Use the following parameters to configure this check:

:exclude_test_files

When true, skips test files (effectively disabling this check). Default: false.

This parameter defaults to false.

General Parameters

Like with all checks, general params can be applied.

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