JuliaFormatter.jl
JuliaFormatter.jl copied to clipboard
Allow preserving style for single-line `if` expressions
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.