Credo.Check.Refactor.MatchInCondition fails when using pipe operator
In credo version 1.7.14, Credo.Check.Refactor.MatchInCondition fails with the error message "Avoid matches in if conditions." when using pipe operator
Example:
# this fails with: "Avoid matches in `if` conditions."
if value = map |> Map.get(key) do
value
else
default
end
# this is fine
if value = Map.get(map, key) do
value
else
default
end
Hi, this is sort of the intended behaviour (only allowing super simple assignments).
But I can see that the latest patch breaks existing patterns and we should at least provide an opt-out config param, so this does not trigger an issue.
Thx for reporting! 🙏
Thanks for reporting this 😀 It should be fixed on master with a new config parameter called allow_operators.
You can try this by setting the Credo dep to
{:credo, github: "rrrene/credo"}
and configuring the check like this:
{Credo.Check.Refactor.MatchInCondition, allow_operators: true}
Please report back if your issue is solved! 👍
Thanks @rrrene! Can confirm it works perfectly with the new setting 🫶
Hello! I don't know if I should report it in this issue or open a new one, but I've got a similar case that I think should be valid:
if token = cookies[@remember_me_cookie] do
(this one is generated by Phoenix scaffolding 😄)
Let me know what you think!
@Gladear an oversight on my part. Sorry! 😬
Should work on master!