OeditusCredo.Check.Warning.CallbackHell (OeditusCredo v0.6.3)

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

Deeply nested case statements create callback hell and reduce readability.

Use with statements or pipe operators for better flow control.

Bad:

case get_user(id) do
  {:ok, user} ->
    case get_account(user) do
      {:ok, account} ->
        case process(account) do
          {:ok, result} -> result
        end
    end
end

Good:

with {:ok, user} <- get_user(id),
     {:ok, account} <- get_account(user),
     {:ok, result} <- process(account) do
  result
end

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.

:max_nesting

Maximum allowed case statement nesting (default: 2)

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.