Skip to content

Commit

Permalink
Fix false positive in MultiAliasImportRequireUseTest
Browse files Browse the repository at this point in the history
Refs #1117
  • Loading branch information
rrrene committed Mar 13, 2024
1 parent a095c30 commit ae78bd8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ defmodule Credo.Check.Consistency.MultiAliasImportRequireUse.Collector do
{ast, {Map.put(acc, mod_name, []), mod_name}}
end

defp traverse({op, _, _}, acc) when op in [:def, :defp] do
{nil, acc}
end

defp traverse({directive, meta, arguments} = ast, {acc, current_module})
when directive in @directives and not is_nil(current_module) do
aliases =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,35 @@ defmodule Credo.Check.Consistency.MultiAliasImportRequireUseTest do
assert issue.trigger == ""
end)
end

test "it should not report errors when #1117" do
[
~S'''
defmodule A.B.Foo do
alias A.{B, C}
end
''',
~S'''
defmodule SomeModule do
@moduledoc false
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
'''
]
|> to_source_files
|> run_check(@described_check)
|> refute_issues()
end
end

0 comments on commit ae78bd8

Please sign in to comment.