OptimumCredo.Check.Readability.ImportOrder (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 imports are more easily scannable by the reader.

# preferred

import ModuleA
import ModuleB
import ModuleC

# NOT preferred

import ModuleA
import ModuleC
import ModuleB

Imports should be alphabetically ordered among their group:

# preferred

import ModuleC
import ModuleD

import ModuleA
import ModuleB

# NOT preferred

import ModuleC
import ModuleD

import ModuleB
import ModuleA

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.