-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Credo.Check.Warning.UnsafeToAtom
warning on compile time created atom
#1148
Comments
Rewriting the code to the following avoids the warning, but I'm unsure if that is the right solution. defmodule Test do
for n <- 1..4 do
def unquote(:erlang.binary_to_atom("fun_#{n}"))(), do: unquote(n)
end
end |
@Wigny Thanks for reporting this 😀 Sorry for the delay. It is now fixed on You can try this by setting the Credo dep to {:credo, github: "rrrene/credo"} Please report back if your issue is solved! 👍 |
Yes, it worked great, thanks! The only case the change didn't cover in our codebase was unquote(context).unquote(:"get_#{type}_by")(id: id) which I believe could have been written as this instead apply(unquote(context), unquote(:"get_#{type}_by"), [[id: id]]) So it is all good IMO. Many thanks for solving it! |
@Wigny Patched the check to cover that case as well. Thx for the input 👍 |
@Wigny This is part of Credo |
Environment
mix credo -v
): 1.7.7-ref.dependabot-hex-gettext-0.26.1.58e9c1b08elixir -v
): Elixir 1.17.2 (compiled with Erlang/OTP 26)What were you trying to do?
Running the
Credo.Check.Warning.UnsafeToAtom
check (mix credo -c Credo.Check.Warning.UnsafeToAtom
) is reporting right now issues for dynamically created atoms passed tounquote()
.Expected outcome
AFAIK dynamically created atoms passed to
unquote()
are generated in compile time and thus should not be reported by this check, given they cannot be exploited in runtime. Thus the following code should not emit the check warning:Actual outcome
Running the check on the code above returns
The text was updated successfully, but these errors were encountered: