From 175d0abfc144c9f1763c031f824eee65f2386d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Mon, 23 Sep 2024 18:35:46 +0200 Subject: [PATCH] Fix false positive for UnsafeToAtom Refs #1148 --- lib/credo/check/warning/unsafe_to_atom.ex | 5 +++++ test/credo/check/warning/unsafe_to_atom_test.exs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/lib/credo/check/warning/unsafe_to_atom.ex b/lib/credo/check/warning/unsafe_to_atom.ex index 921cd1cdf..a96cdeb1b 100644 --- a/lib/credo/check/warning/unsafe_to_atom.ex +++ b/lib/credo/check/warning/unsafe_to_atom.ex @@ -52,6 +52,11 @@ defmodule Credo.Check.Warning.UnsafeToAtom do {nil, issues} end + # module.unquote(:"some_atom") + 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 e3aeb93a1..a73d3f8bf 100644 --- a/test/credo/check/warning/unsafe_to_atom_test.exs +++ b/test/credo/check/warning/unsafe_to_atom_test.exs @@ -35,6 +35,8 @@ defmodule Credo.Check.Warning.UnsafeToAtomTest do def convert_erlang_binary(parameter) do :erlang.binary_to_existing_atom(parameter, :utf8) + + unquote(context).unquote(:"get_#{type}_by")(id: id) end for n <- 1..4 do