fredrikekre / Runic.jl

A code formatter for Julia with rules set in stone.
MIT License
92 stars 2 forks source link

After linebreaks following `=`, indentation is off #39

Closed lmshk closed 3 weeks ago

lmshk commented 1 month ago

For example, Runic reformats

y =
    if x
      1
    else
      2
    end

to

y =
    if x
    1
else
    2
end

which is likely not intended.

(This also applies to short-form function definitions with linebreaks after the =.)

fredrikekre commented 1 month ago

Given the existing rules I would have guessed the result would be

y = if x
        1
    else
        2
    end

but that doesn't look very good either. Probably proper blocks like if-end should have some more "inertia" for changes like this because code like

y = if x
    1
else
    2
end

is pretty common. The style you have with a line break before the if I haven't seen much actually. Would you expect

y =
if x
    1
else
    2
end

?

lmshk commented 1 month ago

I would expect my original form, because the expression as continued on the second line is just indented once. (I usually do this if ?/: does not fit on the first line.)

I'd be fine with your second example as well. (If I write it like that, Runic leaves it as it is.)

adienes commented 1 month ago

I think it should be

y = if x
    1
else
    2
end

the other options present look off to me (including the original example, no offense intended @lmshk 😅)

lmshk commented 1 month ago

That implies that for long conditions, breaking the line then would indent the continuation at the same level as the body. (Similarly for short-form function definitions).

Also, my understanding is that Runic is supposed to leave linebreaks intact; if you prefer y = if x, you can already write it like that and it will not be broken up.

fredrikekre commented 1 month ago

See #42.