-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
The styler auto-formatted the code to an error.
from this:
{
:ok,
assign(socket,
...
manufacturing_countries:
CountriesService.list_by(code: products.mco)
|> Enum.map(&{"#{&1.name}", &1.code}),
...
}
to this:
{
:ok,
assign(socket,
...
manufacturing_countries:
code: products.mco
|> CountriesService.list_by()
|> Enum.map(&{"#{&1.name}", &1.code}),
...
}
which resulted in a syntax error.
The CountriesService.list_by
looks like this:
def list_by(args) do
Enum.reduce(args, Countries, fn {k, v}, query ->
cond do
is_nil(v) -> where(query, [c], is_nil(field(c, ^k)))
true -> where(query, [c], field(c, ^k) == ^v)
end
end)
|> order_by(asc: :sort)
|> Repo.all()
end
My list_by
receives an arguments where I can pass in what I want it to list_by based on the field name. In this case code
but it can be name
for ex. I understand what it's trying to do, and I'm not against it...
If my list_by definition accepts a simpler argument, I'm sure it'll be great. For example:
def list_by_code(code) do
Countries
|> where([c], c.code == ^code)
|> order_by(asc: :sort)
|> Repo.all()
end
then my code would be styled from:
{
:ok,
assign(socket,
...
manufacturing_countries:
CountriesService.list_by_code(products.mco)
|> Enum.map(&{"#{&1.name}", &1.code}),
...
}
to:
{
:ok,
assign(socket,
...
manufacturing_countries:
products.mco
|> CountriesService.list_by_code()
|> Enum.map(&{"#{&1.name}", &1.code}),
...
}
So I just want to ask, is this a niche issue that won't be addressed or considered, or a bad implementation from my part?
Metadata
Metadata
Assignees
Labels
No labels