domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.

Home Page:https://domluna.github.io/JuliaFormatter.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent line breaks with binary operators

sloede opened this issue · comments

With SciML-style formatting, it seems like there is inconsistent line breaking introduced that depends on the type of binary operator. MWE:

julia> using JuliaFormatter

julia> text = """
       a = (1 + 2 + 3
            - 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15)
       b = (1 + 2 + 3
            + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15)
       """;

julia> println(text)
a = (1 + 2 + 3
     - 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15)
b = (1 + 2 + 3
     + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15)


julia> println(format_text(text; style = SciMLStyle(), margin=40))
a = (1 + 2 + 3
     -
     4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 +
     12 + 13 + 14 + 15)
b = (1 + 2 + 3
     + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 +
     12 + 13 + 14 + 15)

IMHO, the formatting for a with the leading - is wrong, since it leaves a single - on an otherwise empty line. If the problematic line starts with a + instead, all is peachy.

cc @SimonCan @jlchan @JoshuaLampert @ranocha