Skip to content

Commit

Permalink
Fix false positive for UnsafeToAtom
Browse files Browse the repository at this point in the history
Refs #1148
  • Loading branch information
rrrene committed Sep 22, 2024
1 parent 1deaa53 commit 5af2172
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/credo/check/warning/unsafe_to_atom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ defmodule Credo.Check.Warning.UnsafeToAtom do
{nil, issues}
end

defp traverse({:unquote, _, [_ | _] = _args}, issues, _) do
{nil, issues}
end

defp traverse(
{:|>, _meta1, [_lhs, {{:., _meta2, call}, meta, args}]} = ast,
issues,
Expand Down
6 changes: 5 additions & 1 deletion test/credo/check/warning/unsafe_to_atom_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Credo.Check.Warning.UnsafeToAtomTest do
#

test "it should NOT report expected code" do
"""
~S"""
defmodule CredoSampleModule do
@test_module_attribute String.to_atom("foo")
@test_module_attribute2 Jason.decode("", keys: :atoms)
Expand Down Expand Up @@ -36,6 +36,10 @@ defmodule Credo.Check.Warning.UnsafeToAtomTest do
def convert_erlang_binary(parameter) do
:erlang.binary_to_existing_atom(parameter, :utf8)
end
for n <- 1..4 do
def unquote(:"fun_#{n}")(), do: unquote(n)
end
end
"""
|> to_source_file()
Expand Down

0 comments on commit 5af2172

Please sign in to comment.