credo icon indicating copy to clipboard operation
credo copied to clipboard

Readability.AliasOrder error for ordered prefixed modules

Open jakub-gonet opened this issue 2 years ago • 0 comments

Environment

  • Credo version (mix credo -v): 1.6.6-ref.master.a28f5362
  • Erlang/Elixir version (elixir -v): Elixir 1.13.4 (compiled with Erlang/OTP 25), Erlang/OTP 25 [erts-13.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
  • Operating system: MacOS

What were you trying to do?

I was expecting this code to be in sorted order:

defmodule M do
  alias A.{X, Y, Z}
  alias A.B.C
end

AliasOrder looks at first module from the group instead of taking base part of alias. This means that this code is correctly ordered according to Credo:

defmodule M do
  alias A.{A, X, Y, Z} # added .A
  alias A.B.C
end

IMO, aliases should sort first basing off prefix and then group.

defmodule M do
  alias A                # sorted
  alias A.{X, Y}         # sorted
  alias A.B.{D, E, F}    # sorted
  alias A.B.{A, D, E, F} # not sorted
end

Expected outcome

No issue is reported.

Actual outcome

Credo.Check.Readability.AliasOrder fails.

jakub-gonet avatar Aug 31 '22 11:08 jakub-gonet