OptimumCredo.Check.Readability.TypespecOrder (OptimumCredo v0.1.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

Alphabetically ordered typespecs are more easily scannable by the reader.

# preferred

@type apple :: String.t()
@type banana :: String.t()
@type cherry :: String.t()

# NOT preferred

@type apple :: String.t()
@type cherry :: String.t()
@type banana :: String.t()

Typespecs should be alphabetically ordered among their group:

# preferred

@type apple :: String.t()
@type banana :: String.t()

@typep color :: String.t()
@typep dimension :: integer()

# NOT preferred

@type banana :: String.t()
@type apple :: String.t()

@typep dimension :: integer()
@typep color :: String.t()

Like all Readability issues, this one is not a technical concern. But you can improve the odds of others reading and liking your code by making it easier to follow.

Check-Specific Parameters

Use the following parameters to configure this check:

:sort_method

The ordering method to use.

Options

  • :alpha - Alphabetical case-insensitive sorting.
  • :ascii - Case-sensitive sorting where upper case characters are ordered
            before their lower case equivalent.

This parameter defaults to :alpha.

General Parameters

Like with all checks, general params can be applied.

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