LexCredo.Check.Warning.UseStartSupervised (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

In test files, use start_supervised!/1 to start processes instead of calling GenServer.start_link/2, Agent.start_link/2, etc. directly.

start_supervised!/1 registers the process with the test supervisor so it is automatically cleaned up between tests, even if the test crashes. Direct start_link calls bypass this and can leave processes running across tests, causing hard-to-reproduce failures.

# BAD
{:ok, pid} = GenServer.start_link(MyServer, [])
{:ok, agent} = Agent.start_link(fn -> %{} end)

# GOOD
pid = start_supervised!(MyServer)
agent = start_supervised!({Agent, fn -> %{} end})

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.