Skip to content

Commit 5af2172

Browse files
committed
Fix false positive for UnsafeToAtom
Refs #1148
1 parent 1deaa53 commit 5af2172

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/credo/check/warning/unsafe_to_atom.ex

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ defmodule Credo.Check.Warning.UnsafeToAtom do
4848
{nil, issues}
4949
end
5050

51+
defp traverse({:unquote, _, [_ | _] = _args}, issues, _) do
52+
{nil, issues}
53+
end
54+
5155
defp traverse(
5256
{:|>, _meta1, [_lhs, {{:., _meta2, call}, meta, args}]} = ast,
5357
issues,

test/credo/check/warning/unsafe_to_atom_test.exs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Credo.Check.Warning.UnsafeToAtomTest do
88
#
99

1010
test "it should NOT report expected code" do
11-
"""
11+
~S"""
1212
defmodule CredoSampleModule do
1313
@test_module_attribute String.to_atom("foo")
1414
@test_module_attribute2 Jason.decode("", keys: :atoms)
@@ -36,6 +36,10 @@ defmodule Credo.Check.Warning.UnsafeToAtomTest do
3636
def convert_erlang_binary(parameter) do
3737
:erlang.binary_to_existing_atom(parameter, :utf8)
3838
end
39+
40+
for n <- 1..4 do
41+
def unquote(:"fun_#{n}")(), do: unquote(n)
42+
end
3943
end
4044
"""
4145
|> to_source_file()

0 commit comments

Comments
 (0)