Just wanting to register my thought while looking at this. But I wish the formatter didn't force newlines in here.
# from this
Ok({
status: code,
headers: [],
body: Str.to_utf8(body),
})
# to this
Ok(
{
status: code,
headers: [],
body: Str.to_utf8(body),
},
)
I made a similar comment in the PR
We should try to fix this before the breaking changes all go through
Another one..
# from this
|> Result.map_err(\err ->
when err is
FileReadErr(path, file_err) ->
Exit(
-1,
"Failed to launch server!\nError reading file $(Path.display(path)):\n\t$(Inspect.to_str(file_err))",
)
FileReadUtf8Err(path, _) ->
Exit(
-2,
"Failed to launch server!\nError: failed to read file $(Path.display(path)) as utf8.",
),
)
# to this
|> Result.map_err(
\err ->
when err is
FileReadErr(path, file_err) ->
Exit(
-1,
"Failed to launch server!\nError reading file $(Path.display(path)):\n\t$(Inspect.to_str(file_err))",
)
FileReadUtf8Err(path, _) ->
Exit(
-2,
"Failed to launch server!\nError: failed to read file $(Path.display(path)) as utf8.",
),
)
And another
# from this
stmt =
Sqlite.prepare!({
path: db_path,
query: "SELECT id, task FROM todos WHERE status = :status;",
})
|> Result.map_err(\err -> ServerErr("Failed to prepare Sqlite statement: $(Inspect.to_str(err))"))
|> try
# to this
stmt =
Sqlite.prepare!(
{
path: db_path,
query: "SELECT id, task FROM todos WHERE status = :status;",
},
)
|> Result.map_err(\err -> ServerErr("Failed to prepare Sqlite statement: $(Inspect.to_str(err))"))
|> try
I don't mean to be nitpicky... just documenting these as I see them
I presume we should be able to fix this by saying anything in a PNC apply node that only has one arg, and that arg is a closure or a record, we allow it to stay on the same lines as the PNC braces
I don't think we need any other examples unless they can't be fixed by this rule
This is the standard style for all collections
And PNC args are in a collection
I think the standard style is Bad
And we should change it
It is for args
(when it's for a single item)
And I’m not disagreeing
Just context setting
It’ll be a small change
I might be able to do it tonight
But in the morning for sure
Definitely not urgent
Yep, not urgent!
I feel so much pressure
"More weight."
To be clear
We are saying that the style for PNC that the trailing paren is always tucked up tight?
Or only with a single multiline arg?
with a single multiline arg IMO
Oh, actually
My definition would be that:
I think your second rule is “any collection that is the sole argument should have no new lines between its braces and the parens of the apply
But other multiline expressions should (another apply, when, if, etc)
When I’m done fixing my moms computer and I can use mine again I’ll type out examples
beeeeeeen there
Richard Feldman said:
beeeeeeen there
Never buy a new SSD for your moms computer for Christmas
Or pay GeekSquad to install it
Those rules make sense
There's the concept floating around of things being "outdentable", and I think we should try to follow that
That's what already drives formatting of things like this:
foo = {
1,
}
rather than:
foo =
{
1,
}
That also applies to closures
(and, IIRC, when, etc etc)
But for example, it doesn't apply to if, since that looks weird with the outdented "else"
So the rule I'd suggest here is:
then we do the formatting suggested here
I'm considering outdentable is somewhat flexible here
In particular, I think this is reasonable to do with single-element lists as well
That makes sense! I don't know how that applies to lambdas, though. I feel like having the closing parens on a new line:
item_list.map(|item|
first = 1 + 2
second = item * 3
first * second
)
Is better than putting the parens on the "outdentable" function body:
item_list.map(|item|
first = 1 + 2
second = item * 3
first * second)
Seems so special-casey
One way to think about this would be the additional requirement that the last line of the inner thing must be “short”. A closing brace is short. A line from a lambda or a when expr is not in general short, so we’d define it as such.
I think when using PNC apply (in Patterns or Exprs) you would like the following:
foo({ a: "Something", b: "Else", c: "Here" }) # Stays the same
foo({
a: "Something",
b: "Else",
c: "Here"
}) # Original
foo({
a: "Something",
b: "Else",
c: "Here",
}) # Formatted
foo(bar, baz, {
a: "Something",
b: "Else",
c: "Here"
}) # Original
foo(bar, baz, {
a: "Something",
b: "Else",
c: "Here",
}) # Formatted
some_fn(\a, b ->
a(b)) # Original
some_fn(\a, b ->
a(b),
) # Formatted
some_fn(foo, bar, \a, b ->
a(b)) # Original
some_fn(foo, bar, \a, b ->
a(b),
) # Formatted
I think the question is what is the handling of when and if? Do we prefer this:
some_fn(foo, bar, when baz is
Ok a -> a
Err _ -> "something else") # Original
some_fn(foo, bar,
when baz is
Ok a -> a
Err _ -> "something else",
) # Formatted
some_fn(foo, bar, if baz then
"this"
else
"something else") # Original
some_fn(foo, bar,
if baz then
"this"
else
"something else",
) # Formatted
Or would you rather have the when on the same line here? I'm assuming the if..then has to be forced on to a new line and outdent the whole thing.
Forcing when and if on a new line is good!
Trying to decide if when and if should make the whole thing multiline and outdented
That's my inclination
Based on what Josh said above, I think if and when aren't "short"
And in addition, they have a target expression they match over that gives context
And it's nice to have that closer to their bodies
Rather than on the same line as the called function, 4 tab widths to the right
Ok, we just have to make sure we define “short”. Like is a nested apply “short”?
Yep, what is "short"
By nested apply do you mean func.call(second_func.call(a, b, c))?
Yep
I think "short" means "this thing has indentation at its end at the same level as its start"
E.g.
func.call({
foo: 1,
bar: 2,
})
Since the } is where func starts its indentation, even though it "outdented" in the record fields
So that would include PNC applies
So all collections and PNC applies(which are an expr and an arg collection)
Where "outdented" means "the middle of this this has indentation"
I guess as long as the func itself is singleline
Ok, that's easy enough logic to implement
Yep, if you do
func.call(arg1, arg2,
|foo| foo + 123)
I'll get this banged out and then time for new lambda syntax
I'd expect that to format to
func.call(
arg1,
arg2,
|foo| foo + 123,
)
Well, I meant something weird like:
func.call(arg1, arg2, (if blah then
func_one
else
func_two)(some_other_arg))
Which would format to this I assume:
func.call(
arg1,
arg2,
(if blah then
func_one
else
func_two)(some_other_arg),
)
Oh lol, yeah
And also, it prints a "YOU'RE FIRED" message
INTO THE SUN"
Perfecto!
Last updated: Jun 16 2026 at 16:19 UTC