Skip to content

Commit

Permalink
Fix MixEnv for module attributes
Browse files Browse the repository at this point in the history
Refs #907
  • Loading branch information
rrrene committed Feb 6, 2022
1 parent 0ef9895 commit 7209eb0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/credo/check/warning/mix_env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ defmodule Credo.Check.Warning.MixEnv do
defp matches?(directory, %Regex{} = regex), do: Regex.match?(regex, directory)
defp matches?(directory, path) when is_binary(path), do: String.starts_with?(directory, path)

defp traverse(
{:@, _,
[
{name, _, args}
]},
issues,
_issue_meta
)
when is_atom(name) and is_list(args) do
{nil, issues}
end

defp traverse(
{{:., _, [{:__aliases__, _, [:Mix]}, :env]}, meta, _arguments} = ast,
issues,
Expand Down
15 changes: 15 additions & 0 deletions test/credo/check/warning/mix_env_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ defmodule Credo.Check.Warning.MixEnvTest do
|> refute_issues()
end

test "it should NOT report on instance in module attributes" do
"""
defmodule CredoSampleModule do
@myvar Mix.env() == :test
def test do
@myvar
end
end
"""
|> to_source_file()
|> run_check(@described_check)
|> refute_issues()
end

#
# cases raising issues
#
Expand Down

0 comments on commit 7209eb0

Please sign in to comment.