ExSlop.Check.Refactor.SortThenReverse (ExSlop v0.3.0)

Copy Markdown 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

Enum.sort/1 |> Enum.reverse/1 should be Enum.sort(:desc). Enum.sort_by/2 |> Enum.reverse/1 should be Enum.sort_by(fun, :desc).

# bad
list |> Enum.sort() |> Enum.reverse()
Enum.reverse(Enum.sort(list))
list |> Enum.sort_by(&fun/1) |> Enum.reverse()

# good
Enum.sort(list, :desc)
Enum.sort_by(list, &fun/1, :desc)

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

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