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

disallow end) #35

Closed
adienes opened this issue Aug 6, 2024 · 5 comments · Fixed by #46
Closed

disallow end) #35

adienes opened this issue Aug 6, 2024 · 5 comments · Fixed by #46

Comments

@adienes
Copy link

adienes commented Aug 6, 2024

I feel very strongly that end) should never appear in my code, and similarly (keyword. I understand that opinions may differ, but for my part I would never use a formatter that declines to reformat all appearance of these bigrams

@fredrikekre
Copy link
Owner

Do you have a specific example where Runic outputs end)?

@adienes
Copy link
Author

adienes commented Aug 6, 2024

sum(filter(rand(10000)) do x 2 * x end) is left unchanged

I would only ever write this as

sum(
    filter(rand(10000)) do x
        2 * x
    end,
)

or

sum(
    filter(
        rand(10000),
    ) do x
        2 * x
    end,
)

although realistically I probably won't put do .. end inside an argument in the first place, but that's outside the scope of a formatter

I'm well aware that the rewriting I propose looks kinda ugly as well & verbose in the number of lines --- but I think that is intentionally a good thing. if the formatter does not rewrite my code in a way that looks nice that's probably a signal that I need to break up some of the logic anyway (because end, is similarly offensive, but unavoidable in argument lists)

@fredrikekre
Copy link
Owner

fredrikekre commented Aug 6, 2024

I see, for some reason I thought you only disliked \n${indent}end).

The current reason Runic doesn't change anything with your do example is that expressions that are single line stay single line. I think the rule we can add here (which I already had in mind) is that code blocks should be surrounded by newlines. This rule would insert newlines like

sum(filter(rand(10000)) do x
2 * x
end)

which would then be formatted as

sum(
    filter(rand(10000)) do x
        2 * x
    end,
)

by already existing rules.

@adienes
Copy link
Author

adienes commented Aug 6, 2024

that would definitely work for me

although I don't know how controversial my opinion is on this preference --- possibly many people don't mind (or even prefer) single line with end)

fredrikekre added a commit that referenced this issue Aug 21, 2024
This patch introduces formatting for all blocklike constructs
(`if`/`try`/`function`/`begin`/`for`/`while`/...) such that inner block
always start and end with a newline character.

For example,
```julia
if x print("x") else print("y") end
```
will be reformatted as
```julia
if x
    print("x")
else
    print("y")
end
```

An exception is (currently) made for comments, for example
```julia
if x # comment
    print("x")
end
```
will *not* be formatted as
```julia
if x
    # comment
    print("x")
end
```
even though the comment is technically inside the block.

Closes #35.
@fredrikekre
Copy link
Owner

With #46

sum(filter(rand(10000)) do x 2 * x end)

becomes

sum(
    filter(rand(10000)) do x
        2 * x
    end,
)

fredrikekre added a commit that referenced this issue Aug 21, 2024
This patch introduces formatting for all blocklike constructs
(`if`/`try`/`function`/`begin`/`for`/`while`/...) such that inner block
always start and end with a newline character.

For example,
```julia
if x print("x") else print("y") end
```
will be reformatted as
```julia
if x
    print("x")
else
    print("y")
end
```

An exception is (currently) made for comments, for example
```julia
if x # comment
    print("x")
end
```
will *not* be formatted as
```julia
if x
    # comment
    print("x")
end
```
even though the comment is technically inside the block.

Closes #35.
fredrikekre added a commit that referenced this issue Aug 21, 2024
This patch introduces formatting for all blocklike constructs
(`if`/`try`/`function`/`begin`/`for`/`while`/...) such that inner block
always start and end with a newline character.

For example,
```julia
if x print("x") else print("y") end
```
will be reformatted as
```julia
if x
    print("x")
else
    print("y")
end
```

An exception is (currently) made for comments, for example
```julia
if x # comment
    print("x")
end
```
will *not* be formatted as
```julia
if x
    # comment
    print("x")
end
```
even though the comment is technically inside the block.

Closes #35.
fredrikekre added a commit that referenced this issue Aug 21, 2024
This patch introduces formatting for all blocklike constructs
(`if`/`try`/`function`/`begin`/`for`/`while`/...) such that inner block
always start and end with a newline character.

For example,
```julia
if x print("x") else print("y") end
```
will be reformatted as
```julia
if x
    print("x")
else
    print("y")
end
```

An exception is (currently) made for comments, for example
```julia
if x # comment
    print("x")
end
```
will *not* be formatted as
```julia
if x
    # comment
    print("x")
end
```
even though the comment is technically inside the block.

Closes #35.
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

Successfully merging a pull request may close this issue.

2 participants