Skip to content

Commit

Permalink
Fix false positive in UnusedFunctionReturnHelper
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
rrrene committed Mar 15, 2016
1 parent c906006 commit d761de5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/credo/check/warning/unused_function_return_helper.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Credo.Check.Warning.UnusedFunctionReturnHelper do
@explanation ""
@def_ops [:def, :defp, :defmacro]
@block_ops [:if, :unless, :case, :for, :quote, :try, :after, :rescue]
@block_ops [:if, :unless, :case, :quote, :try, :after, :rescue]

alias Credo.Check.CodeHelper

Expand Down Expand Up @@ -83,6 +83,20 @@ defmodule Credo.Check.Warning.UnusedFunctionReturnHelper do
end
end
end
defp valid_call_to_string_mod?({:for, _meta, arguments} = ast, call_to_string, last_call_in_def, calls_in_block_above) when is_list(arguments) do
arguments_without_do_block = arguments |> Enum.slice(0..-2)

if CodeHelper.contains_child?(arguments_without_do_block, call_to_string) do
true
else
[
arguments |> CodeHelper.do_block_for!,
arguments |> CodeHelper.else_block_for!,
]
|> Enum.reject(&is_nil/1)
|> Enum.any?(&valid_call_to_string_mod_in_block?(&1, ast, call_to_string, last_call_in_def, calls_in_block_above))
end
end
defp valid_call_to_string_mod?({:cond, _meta, arguments} = ast, call_to_string, last_call_in_def, calls_in_block_above) do
[
arguments |> CodeHelper.do_block_for!,
Expand Down

0 comments on commit d761de5

Please sign in to comment.