Skip to content

Commit

Permalink
Check in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Wigny committed Dec 9, 2024
1 parent 2d36c6d commit 264ce87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Credo.Check.Consistency.UnusedVariableNames.Collector do
end

defp traverse(callback, {def, _, [{_, _, params} | _]} = ast, acc)
when def in [:def, :defp] do
when def in [:def, :defp, :defmacro, :defmacrop] do
{ast, reduce_unused_variables(params, callback, acc)}
end

Expand Down
30 changes: 30 additions & 0 deletions test/credo/check/consistency/unused_variable_names_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,36 @@ defmodule Credo.Check.Consistency.UnusedVariableNamesTest do
end)
end

test "it should report a violation for different naming schemes with a macro (expects meaningful)" do
[
"""
defmodule Credo.SampleOne do
defmodule Foo do
defmacro __using__(_) do
end
end
def bar(_opts) do
end
end
""",
"""
defmodule Credo.SampleTwo do
defmodule Foo do
defmacrop bar(_opts) do
end
end
end
"""
]
|> to_source_files()
|> run_check(@described_check)
|> assert_issue(fn issue ->
assert "_" == issue.trigger
assert 3 == issue.line_no
end)
end

test "it should report a violation for naming schemes other than the forced one" do
[
"""
Expand Down

0 comments on commit 264ce87

Please sign in to comment.