BlueStyle
BlueStyle copied to clipboard
Simplify some current guidance to "have a blank line between multi-line blocks"?
Noticed when writing up https://github.com/domluna/JuliaFormatter.jl/issues/283 (see https://github.com/domluna/JuliaFormatter.jl/issues/283#issuecomment-687795763, related to #7), but better to discuss here :)
We currently have two rules:
- Use blank-lines to separate different multi-line blocks.
- Use line breaks between control flow statements and returns.
i wasn't sure how to translate the first one into a rule for a Formatter to follow, unless it just mean "have a blank line after end". If it can be translated to that, then the second one is just a special-case (assuming "control flow" here means only while.. end and if... end statements, which it seems to be, based on the example given).
I suggest we simplify these two rules in one. Below are some options for the new rule:
Option 1:
- Add a blank line after
endin multi-line blocks
# Yes:
if foo
println("Hi")
end
for i in 1:10
println(i)
end
# No:
if foo
println("Hi")
end
for i in 1:10
println(i)
end
# Yes:
function foo(bar; verbose=false)
if verbose
println("baz")
end
return bar
end
# No:
function foo(bar; verbose=false)
if verbose
println("baz")
end
return bar
end
- Note that in this second example, the
Nocase is currently listed asOK.
Option 2
- Add a blank line between multiple multi-line blocks
# Yes:
if foo
println("Hi")
end
for i in 1:10
println(i)
end
# No:
if foo
println("Hi")
end
for i in 1:10
println(i)
end
- Note we now longer give an opinion on the second example above (the blank line after
end/ beforereturn)
Option 3
- Stop giving guidance on this
For what it is worth, i'd happily go with Option 3. In practice, i'm happy enough writing code that follows Option 2, but Option 1 seems a little too fussy to me.
I prefer option 1, I do not like option 3 very much