fredrikekre/Runic.jl

disallow `end)`

Closed this issue · 5 comments

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

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

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)

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.

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)

With #46

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

becomes

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