OptimumCredo.Check.Readability.MaybePrefix (OptimumCredo v0.5.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 low and works with any version of Elixir.

Explanation

Functions that may or may not act on their first argument start with maybe_.

Bad

defp load_user(socket, nil), do: socket
defp load_user(socket, id), do: assign(socket, :user, Accounts.get_user(id))

Good

defp maybe_load_user(socket, nil), do: socket
defp maybe_load_user(socket, id), do: assign(socket, :user, Accounts.get_user(id))

The check detects the shape (the first argument returned unchanged on one path, a call on another); it cannot tell whether the call has side effects.

Check-Specific Parameters

Use the following parameters to configure this check:

:prefix

Required name prefix.

This parameter defaults to "maybe_".

:allowed_prefixes

Additional accepted prefixes.

This parameter defaults to [].

:ignore_functions

Function names that are exempt.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

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