Soundcheck.Check.Warning.StreamConsumedOutsideFor (soundcheck 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 high and works with any version of Elixir.

Explanation

Flags @streams.name passed straight to an enumerating function (Enum, List, Stream, Map, MapSet, Keyword, length/1, hd/1, tl/1). LiveView raises at render time, because a stream is not a list: its items are not kept on the server.

Before:

<p>{length(@streams.posts)} posts</p>

After: keep a separate count assign.

<p>{@post_count} posts</p>

Allowed: :for={{id, item} <- @streams.name}, <%= for {id, item} <- @streams.name do %>, and passing the stream to a component attribute (<.table rows={@streams.posts}>), which iterates it.

Confidence: high. Tier: syntactic (works without compiling).

Check-Specific Parameters

Use the following parameters to configure this check:

:excluded_paths

Paths to skip (atoms, binaries as path segments, or regexes).

This parameter defaults to [~r/\/test\//, "test"].

:strict

Unused.

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.