rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

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

Closed sl1depengwyn closed 3 months ago

sl1depengwyn commented 5 months ago

Environment

Elixir 1.14.5 (compiled with Erlang/OTP 25)

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>
rrrene commented 5 months ago

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?

sl1depengwyn commented 5 months ago

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

rrrene commented 5 months ago

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 commented 3 months ago

This is live in v1.7.6 🎉