credo icon indicating copy to clipboard operation
credo copied to clipboard

"Most of the time you are using the multi-alias/require/import/use syntax..." with compile_env

Open sl1depengwyn opened this issue 1 year ago • 3 comments

Environment

  • Credo version (mix credo -v): 1.7.4-ref.np-interpret-user-ops.b900d15036+uncommittedchanges
  • Erlang/Elixir version (elixir -v): Erlang/OTP 25 [erts-13.2.2.5] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1]

Elixir 1.14.5 (compiled with Erlang/OTP 25)

  • Operating system: MacOS 14

What were you trying to do?

defmodule SomeModule do
  alias A.B.Foo

...

  case Application.compile_env(:app, SomeModule)[:use_bar] do
    "true" ->
      defp a() do
        alias A.B.Bar
        Bar.f()
      end

    _ ->
      defp a(), do: nil
  end
end

Expected outcome

No warnings from credo

Actual outcome

  Consistency
┃
┃ [C] ↗ Most of the time you are using the multi-alias/require/import/use syntax, but here you are using
┃       multiple single directives
┃       <path>

sl1depengwyn avatar Mar 13 '24 07:03 sl1depengwyn

Hi, I can't reproduce this.

I have used this code:

defmodule SomeModule do
  alias A.B.Foo

  case Application.compile_env(:app, SomeModule)[:use_bar] do
    "true" ->
      defp a() do
        alias A.B.Bar
        Bar.f()
      end

    _ ->
      defp a(), do: nil
  end
end

Can you provide any additional details or create a minimal reproducible example?

rrrene avatar Mar 13 '24 11:03 rrrene

Here it is: https://github.com/sl1depengwyn/credo-multi-alias-example/tree/main

sl1depengwyn avatar Mar 13 '24 19:03 sl1depengwyn

Thanks for reporting this 😀 It is now fixed on master.

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! 👍

rrrene avatar Mar 13 '24 20:03 rrrene

This is live in v1.7.6 🎉

rrrene avatar May 09 '24 11:05 rrrene