Eunomo.Formatter.AlphabeticalImportSorter (eunomo v0.1.3)

Sorts import definitions alphabetically.

The sorting does not happen globally. Instead each "import block" is sorted separately. An "import block" is a set of import expressions that are not separated by at least one empty newline or other non-import expressions.

Only the order of lines is modified by this formatter. Neither the overall number of lines nor the content of a single line will change.

Examples

iex> code_snippet = """
...> import Eunomo.Z.{L, I}
...> import Eunomo.Z, only: [hello_world: 0]
...> import Eunomo.{
...>   L,
...>   B,
...>   # test
...> }
...> import Eunomo.C
...> import B, expect: [callback: 1]
...> \nimport Eunomo.PG.Repo
...> import A
...> import Eunomo.Patient
...> """
...> Eunomo.format_string(code_snippet, [Eunomo.Formatter.AlphabeticalImportSorter])
"""
import B, expect: [callback: 1]
import Eunomo.C
import Eunomo.Z, only: [hello_world: 0]
import Eunomo.Z.{L, I}
import Eunomo.{
  L,
  B,
  # test
}
\nimport A
import Eunomo.Patient
import Eunomo.PG.Repo
"""