View Source Credo.Check.Refactor.Nesting (Credo v1.7.4)


This check is enabled by default.

Learn how to disable it via .credo.exs.

This check has a base priority of 0 and works with any version of Elixir.


Code should not be nested more than once inside a function.

defmodule CredoSampleModule do
  def some_function(parameter1, parameter2) do
    Enum.reduce(var1, list, fn({_hash, nodes}, list) ->
      filenames = nodes |>

      Enum.reduce(list, [], fn(item, acc) ->
        if item.filename do
          item               # <-- this is nested 3 levels deep
        acc ++ [item]

At this point it might be a good idea to refactor the code to separate the different loops and conditions.

Check-Specific Parameters

Use the following parameters to configure this check:


The maximum number of levels code should be nested.

This parameter defaults to 2.

General Parameters

Like with all checks, general params can be applied.

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