Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some current guidance to "have a blank line between multi-line blocks"? #61

Open
nickrobinson251 opened this issue Sep 6, 2020 · 1 comment

Comments

@nickrobinson251
Copy link
Contributor

nickrobinson251 commented Sep 6, 2020

Noticed when writing up domluna/JuliaFormatter.jl#283 (see domluna/JuliaFormatter.jl#283 (comment), 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 end in 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 No case is currently listed as OK.

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 / before return)

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.

@iamed2
Copy link
Collaborator

iamed2 commented Sep 9, 2020

I prefer option 1, I do not like option 3 very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants