Skip to content

Commit

Permalink
Check in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Wigny committed Dec 9, 2024
1 parent f14e915 commit 2d36c6d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ defmodule Credo.Check.Consistency.UnusedVariableNames.Collector do
{left, right}, param_acc ->
reduce_unused_variables([left, right], callback, param_acc)

list_ast, param_acc when is_list(list_ast) ->
reduce_unused_variables(list_ast, callback, param_acc)

param_ast, param_acc ->
if unused_variable_ast?(param_ast) do
IO.inspect(param_ast, label: :param_ast)
callback.(param_ast, param_acc)
else
param_acc
Expand Down
34 changes: 33 additions & 1 deletion test/credo/check/consistency/unused_variable_names_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ defmodule Credo.Check.Consistency.UnusedVariableNamesTest do
end)
end

test "it should report a violation for different naming schemes with two elem tuple match (expects meaningful)" do
test "it should report a violation for different naming schemes in a two elem tuple match (expects meaningful)" do
[
"""
defmodule Credo.SampleOne do
Expand Down Expand Up @@ -254,6 +254,38 @@ defmodule Credo.Check.Consistency.UnusedVariableNamesTest do
end)
end

test "it should report a violation for different naming schemes with a list (expects meaningful)" do
[
"""
defmodule Credo.SampleOne do
defmodule Foo do
def bar(list) do
case list do
[] -> :empty
[head | _] -> head
end
end
end
end
""",
"""
defmodule Credo.SampleTwo do
defmodule Foo do
def bar([_a, _b | rest]) do
rest
end
end
end
"""
]
|> to_source_files()
|> run_check(@described_check)
|> assert_issue(fn issue ->
assert "_" == issue.trigger
assert 6 == 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 2d36c6d

Please sign in to comment.