JuliaFormatter.jl icon indicating copy to clipboard operation
JuliaFormatter.jl copied to clipboard

Allow preserving style for single-line `if` expressions

Open serenity4 opened this issue 3 years ago • 0 comments

Single-line if expressions currently get split into multiple lines. Would it be possible to keep the style to preserve the first version below?

Before formatting:

function f()
  if rand() < 0.5 return 2 end
  0
end

After formatting (if gets split):

function f()
    if rand() < 0.5
        return 2
    end
    0
end

While the splitting is probably desired in most cases, the case above is equivalent to a short-circuiting && so it's a bit of a corner case, but still it could be made more readable by keeping it in one line.

serenity4 avatar Dec 03 '21 17:12 serenity4