View Source Credo.Check.Refactor.ABCSize (Credo v1.7.5)
Basics
This check is disabled by default.
Learn how to enable it via
.credo.exs
.
This check is tagged
:controversial
This means that this check is more opinionated than others and not for everyone's taste.
This check has a base priority of 0
and works with any version of Elixir.
Explanation
The ABC size describes a metric based on assignments, branches and conditions.
A high ABC size is a hint that a function might be doing "more" than it should.
As always: Take any metric with a grain of salt. Since this one was originally introduced for C, C++ and Java, we still have to see whether or not this can be a useful metric in a declarative language like Elixir.
Check-Specific Parameters
Use the following parameters to configure this check:
:max_size
The maximum ABC size a function should have.
This parameter defaults to 30
.
:excluded_functions
All functions listed will be ignored.
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.
Summary
Functions
Returns the ABC size for the block inside the given AST, which is expected to represent a function or macro definition.
Functions
Returns the ABC size for the block inside the given AST, which is expected to represent a function or macro definition.
iex> {:def, [line: 1],
...> [
...> {:first_fun, [line: 1], nil},
...> [do: {:=, [line: 2], [{:x, [line: 2], nil}, 1]}]
...> ]
...> } |> Credo.Check.Refactor.ABCSize.abc_size
1.0