From 5af2172db424dbd9a75a297d04ab2d89b220a8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Sun, 22 Sep 2024 11:45:29 +0200 Subject: [PATCH] Fix false positive for UnsafeToAtom Refs #1148 --- lib/credo/check/warning/unsafe_to_atom.ex | 4 ++++ test/credo/check/warning/unsafe_to_atom_test.exs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/credo/check/warning/unsafe_to_atom.ex b/lib/credo/check/warning/unsafe_to_atom.ex index afeaa8c8d..921cd1cdf 100644 --- a/lib/credo/check/warning/unsafe_to_atom.ex +++ b/lib/credo/check/warning/unsafe_to_atom.ex @@ -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, diff --git a/test/credo/check/warning/unsafe_to_atom_test.exs b/test/credo/check/warning/unsafe_to_atom_test.exs index 9bead880a..e3aeb93a1 100644 --- a/test/credo/check/warning/unsafe_to_atom_test.exs +++ b/test/credo/check/warning/unsafe_to_atom_test.exs @@ -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) @@ -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()