Skip to content

SciMLStyle leaves wrapped do-block arguments unindented after macro call #1200

Description

@MilesCranmerBot

Reproducer

With JuliaFormatter's SciMLStyle, a macro call with a do block whose arguments wrap over multiple lines produces unindented do arguments:

using JuliaFormatter

src = """
expr_spec = @template_spec(parameters=(p1=10, p2=10, p3=1),  expressions=(f, g))  do x1,
x2,
class

    x1 * 2
end
"""

print(format_text(src; style=SciMLStyle(), margin=92))

On JuliaFormatter v2.10.1 this gives:

expr_spec = @template_spec(parameters=(p1 = 10, p2 = 10, p3 = 1), expressions=(f, g)
) do x1,
x2,
class
    x1 * 2
end

The surprising part is that the continuation arguments after do x1, are at column 1, which looks accidental/unstable and is hard to read.

For comparison, BlueStyle formats the same snippet as:

expr_spec = @template_spec(
    parameters=(p1=10, p2=10, p3=1), expressions=(f, g)
) do x1, x2, class
    x1 * 2
end

and YASStyle indents the wrapped do arguments under the first argument.

Version notes

I checked a small matrix on Julia 1.12.5:

  • v1.0.55 through v2.4.0: already put x2, and class at column 1 for this SciMLStyle example.
  • v2.5.0/v2.6.0: output changed further and preserved the original double spaces around the macro-call / do, and also produced x1*2 in the body.
  • v2.6.15 through v2.10.1: spaces in the body are fixed again, but the unindented multiline do arguments remain; the closing ) before do also ends up on its own line for this case.

So the unindented do-argument behavior is not a brand-new v2.10 regression, but the macro-call formatting around this case did change noticeably between v2.4.0 and v2.5.0.

Expected

I would expect the continuation arguments to either stay on one line when they fit:

) do x1, x2, class

or, if split, to be indented consistently, e.g.

) do x1,
    x2,
    class

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions