diff --git a/lib/credo/check/warning/unused_function_return_helper.ex b/lib/credo/check/warning/unused_function_return_helper.ex index fefbd04cf..611a52a03 100644 --- a/lib/credo/check/warning/unused_function_return_helper.ex +++ b/lib/credo/check/warning/unused_function_return_helper.ex @@ -230,6 +230,22 @@ defmodule Credo.Check.Warning.UnusedFunctionReturnHelper do end end + # anon_fun.() + defp verify_candidate( + {{:., _, [{fun_name, _, nil}]}, _, arguments} = ast, + :not_verified = acc, + candidate + ) + when is_atom(fun_name) and is_list(arguments) do + # IO.inspect(ast, label: "anon_fun.() (#{Macro.to_string(candidate)} #{acc})") + + if Credo.Code.contains_child?(arguments, candidate) do + {nil, :VERIFIED} + else + {ast, acc} + end + end + # module.my_fun() defp verify_candidate( {{:., _, [{module, _, []}, fun_name]}, _, arguments} = ast, @@ -278,14 +294,6 @@ defmodule Credo.Check.Warning.UnusedFunctionReturnHelper do end end - {:., [line: 3, column: 31], - [ - {{:., [line: 3, column: 22], - [{:__aliases__, [line: 3, column: 5], [:CredoSampleModule]}, :runner]}, - [line: 3, column: 23], []}, - :do_some_function - ]} - # module.my_fun() defp verify_candidate( {{:., _, [{module_variable, _, nil}, fun_name]}, _, arguments} = ast, diff --git a/test/credo/check/warning/unused_enum_operation_test.exs b/test/credo/check/warning/unused_enum_operation_test.exs index 058d14c37..9ce595fa5 100644 --- a/test/credo/check/warning/unused_enum_operation_test.exs +++ b/test/credo/check/warning/unused_enum_operation_test.exs @@ -145,6 +145,21 @@ defmodule Credo.Check.Warning.UnusedEnumOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside an anon function call" do + """ + defmodule CredoSampleModule do + def fun(anon_func) do + anon_func.(Enum.random(1..10)) + + :ok + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do