Permalink
Browse files

Fix false positive for MapInto

Fixes #627
  • Loading branch information...
rrrene committed Feb 3, 2019
1 parent 202e4f6 commit 9b94e349af8f0286e68c6d9b6aa34bc64799ac43
Showing with 13 additions and 2 deletions.
  1. +7 −2 lib/credo/check/refactor/map_into.ex
  2. +6 −0 test/credo/check/refactor/map_into_test.exs
@@ -37,6 +37,7 @@ defmodule Credo.Check.Refactor.MapInto do
issue_meta
) do
new_issue = issue_for(issue_meta, meta[:line], "map_into")

{ast, issues ++ List.wrap(new_issue)}
end

@@ -50,6 +51,7 @@ defmodule Credo.Check.Refactor.MapInto do
issue_meta
) do
new_issue = issue_for(issue_meta, meta[:line], "map_into")

{ast, issues ++ List.wrap(new_issue)}
end

@@ -63,6 +65,7 @@ defmodule Credo.Check.Refactor.MapInto do
issue_meta
) do
new_issue = issue_for(issue_meta, meta[:line], "map_into")

{ast, issues ++ List.wrap(new_issue)}
end

@@ -74,12 +77,14 @@ defmodule Credo.Check.Refactor.MapInto do
_,
{{:., _, [{:__aliases__, _, [:Enum]}, :map]}, _, _}
]},
{{:., _, [{:__aliases__, _, [:Enum]}, :into]}, _, _}
{{:., _, [{:__aliases__, _, [:Enum]}, :into]}, _, into_args}
]} = ast,
issues,
issue_meta
) do
)
when length(into_args) == 1 do
new_issue = issue_for(issue_meta, meta[:line], "map_into")

{ast, issues ++ List.wrap(new_issue)}
end

@@ -12,6 +12,12 @@ defmodule Credo.Check.Refactor.MapIntoTest do
defmodule Credo.Sample.Module do
def some_function(p1, p2, p3, p4, p5) do
Enum.into([:apple, :banana, :carrot], %{}, &({&1, to_string(&1)}))
my_list
|> Enum.map(&square/1)
|> Enum.into(%{}, &to_tuple/1)
Enum.into(Enum.map(my_list, &square/1), %{}, &to_tuple/1)
end
end
"""

0 comments on commit 9b94e34

Please sign in to comment.