Skip to content

Commit

Permalink
Merge branch 'master' into remove-unused-function
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene authored Nov 17, 2023
2 parents b2b1a9b + a8f661f commit a3ce766
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/credo/check/warning/mix_env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ defmodule Credo.Check.Warning.MixEnv do

for op <- @def_ops do
# catch variables named e.g. `defp`
defp traverse({unquote(op), _, nil} = ast, issues, _issue_meta) do
{ast, issues}
end

defp traverse({unquote(op), _, _body} = ast, issues, issue_meta) do
{ast, issues ++ Credo.Code.prewalk(ast, &traverse_defs(&1, &2, issue_meta))}
end
Expand Down
14 changes: 14 additions & 0 deletions test/credo/check/warning/mix_env_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,18 @@ defmodule Credo.Check.Warning.MixEnvTest do
|> run_check(@described_check)
|> assert_issue()
end

test "it should report violations from variables named like def operations" do
"""
defmodule CredoSampleModule do
def some_function do
def = Mix.env()
defp = &Mix.env/0
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> assert_issues()
end
end

0 comments on commit a3ce766

Please sign in to comment.