Add a check for assignment in with conditions#1210
Add a check for assignment in with conditions#1210ryanwinchester wants to merge 1 commit intorrrene:masterfrom
Conversation
|
Hi, thx for putting this together! I am in favor of merging it, except there is one case not covered: defmodule CredoSampleModule do
def some_function(id) do
with {:ok, user} <- get_user(id),
token = ExternalLib.get_user_token(user.id),
{:ok, profile} <- get_profile(user, token) do
{:ok, %{user: user, profile: profile}}
else
{:error, :something}
end
end
endYour check says "there can't be any assignments, ever" and I would love to have a configuration option to say: "Assignments only in the middle of the clauses, if their return value is needed for the chain" ( Because how would you model the above example otherwise? |
with defmodule CredoSampleModule do
def some_function(id) do
with {:ok, user} <- get_user(id),
token <- ExternalLib.get_user_token(user.id),
{:ok, profile} <- get_profile(user, token) do
{:ok, %{user: user, profile: profile}}
else
{:error, :something}
end
end
endbut also not confusing newcomers if they switch it to ran into almost the exact same scenario recently with someone who just started with Elixir
There is already a check for the first and last condition in the I'm personally okay with |
Some folks hate this, and it can trip people up.