OptimumCredo.Check.Readability.FunctionOrder (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

Keep function definitions in a predictable order. Choose one convention with function_order: alphabetical within public and private groups, or private functions below their first caller.

Bad (:alphabetical)

def update(thing), do: thing
def create(thing), do: thing
def delete(thing), do: thing

Good (:alphabetical)

def create(thing), do: thing
def delete(thing), do: thing
def update(thing), do: thing

Callbacks marked with @impl are ignored. Callers are matched by name and arity. The check does nothing until function_order is set to :alphabetical or :callers_first.

Check-Specific Parameters

Use the following parameters to configure this check:

:function_order

:off (default), :alphabetical, or :callers_first.

This parameter defaults to :off.

:min_run

Minimum functions in a visibility group for :alphabetical.

This parameter defaults to 3.

General Parameters

Like with all checks, general params can be applied.

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