Skip to content

Commit

Permalink
Fix false positive on UnusedFunctionReturnHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Apr 13, 2018
1 parent 5287075 commit 517699f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/credo/check/warning/unused_function_return_helper.ex
Expand Up @@ -194,6 +194,22 @@ defmodule Credo.Check.Warning.UnusedFunctionReturnHelper do
end
end

# module.my_fun()
defp verify_candidate(
{{:., _, [{module, _, []}, fun_name]}, _, arguments} = ast,
:not_verified = acc,
candidate
)
when is_atom(fun_name) and is_atom(module) and is_list(arguments) do
# IO.inspect(ast, label: "Mod.fun() (#{Macro.to_string(candidate)} #{acc})")

if CodeHelper.contains_child?(arguments, candidate) do
{nil, :VERIFIED}
else
{ast, acc}
end
end

# MyModule.my_fun()
defp verify_candidate(
{{:., _, [{:__aliases__, _, mods}, fun_name]}, _, arguments} = ast,
Expand Down
26 changes: 26 additions & 0 deletions test/credo/check/warning/unused_path_operation_test.exs
Expand Up @@ -10,6 +10,32 @@ defmodule Credo.Check.Warning.UnusedPathOperationTest do
Path.join(parameter1) + parameter2
end
end
defmodule CredoExample do
def error do
module().call(Path.join("~", "foo"))
"something"
end
def no_error(:one) do
call(Path.join("~", "foo"))
"something"
end
def no_error(:two) do
module().call(Path.join("~", "foo"))
end
defp call(path) do
IO.puts path
end
defp module do
CredoExample
end
end
"""
|> to_source_file
|> refute_issues(@described_check)
Expand Down

0 comments on commit 517699f

Please sign in to comment.