StyLua icon indicating copy to clipboard operation
StyLua copied to clipboard

Empty line between if-else-if ladders gets removed thus ruining readablity.

Open Aspecky opened this issue 3 years ago • 9 comments

Lot of times I have these inevitable if-else ladders and it gets a bit hard finding my way through them which is why I leave an blank line before my next elseif so it becomes easier to read, like this:

if true then
    local var = 2
    var += 1
    var += 1
    var += 1
	
elseif true and not true then
    local var = 3
    var += 1
    var += 1
    var += 1
end

But the formatter removes that blank line and kills readability for me, so it becomes like this:

if true then
    local var = 2
    var += 1
    var += 1
    var += 1
elseif true and not true then
    local var = 3
    var += 1
    var += 1
    var += 1
end

And it gets much worse the longer the code is and the longer the ladder is. I think there should be an option to leave blank lines there for people like me.

Aspecky avatar Jan 31 '22 00:01 Aspecky

I do the same thing, this would be much appreciated.

dphfox avatar Jan 31 '22 12:01 dphfox

Interesting, personally I find the difference in indent helps, but I can definitely see where you are coming from.

I wonder if we should just leave a newline at the end of an if block if one was present originally. It might be reasonable rather than a whole option for it. Also, do you only keep this newline for blocks above another block? (i.e., you don't have a newline between the last block and end)

JohnnyMorganz avatar Jan 31 '22 15:01 JohnnyMorganz

Oh right, I forgot to mention that, if there was an empty line in the last end, it should be removed, because it doesn't serve any purpose. So this:

if true then
    local var = 2
    var += 1
    var += 1
    var += 1
	
elseif true and not true then
    local var = 3
    var += 1
    var += 1
    var += 1

end

Would become this:

if true then
    local var = 2
    var += 1
    var += 1
    var += 1
	
elseif true and not true then
    local var = 3
    var += 1
    var += 1
    var += 1
end

Aspecky avatar Jan 31 '22 18:01 Aspecky

Personally, I do not like the idea of this happening. I would want StyLua to reformat this and remove this blank line in code I format with it. Part of why I use StyLua is to remove formatting decisions like this and so my code is formatted the same each time.

LastTalon avatar Jan 31 '22 18:01 LastTalon

Personally, I do not like the idea of this happening. I would want StyLua to reformat this and remove this blank line in code I format with it. Part of why I use StyLua is to remove formatting decisions like this and so my code is formatted the same each time.

Which is why this could be a toggleable option in the settings, that will satisfy both parties.

Aspecky avatar Jan 31 '22 20:01 Aspecky

Which is why this could be a toggleable option in the settings, that will satisfy both parties.

Yeah, this would be better. I was mostly referring to this:

I wonder if we should just leave a newline at the end of an if block if one was present originally.

LastTalon avatar Jan 31 '22 20:01 LastTalon

I wonder if we should just leave a newline at the end of an if block if one was present originally.

No, that would ruin the reproducibility. Personally this is an option I won't use. I don't care if the feature gets added, but having it decide whether or not to do something based on the input formatting ruins the predictability of what would come out. Putting it behind an configuration option would allow it it exist as a feature without messing up those of us that would prefer actual normalization.

alerque avatar Dec 23 '23 15:12 alerque

+1 there. I no longer agree with the idea of relying on input to determine output. The most major problem being that in a project it now depends on how the user originally formatted the code (and then style nits all come back again! "Please delete this newline").

This feature, if added, would be added behind an option and would apply in all cases

JohnnyMorganz avatar Dec 23 '23 17:12 JohnnyMorganz