StyLua icon indicating copy to clipboard operation
StyLua copied to clipboard

`local var; var = ...` looks better in the same line (suggestion)

Open Aspecky opened this issue 2 years ago • 3 comments

Sometimes we use a local variable inside an anonymous function like so:

local connection
connection = ...(function()
    connection:Disconnect()
end)

And doing this makes it look better imo:

local connection; connection = ...(function()
    connection:Disconnect()
end)

Is there a chance we could have this as a configuration flag?

Aspecky avatar Sep 06 '22 20:09 Aspecky

This is an interesting suggestion.

For simplicity and consistency, I am somewhat hesitant about adding something like this in, but I will give it a think

JohnnyMorganz avatar Sep 11 '22 15:09 JohnnyMorganz

A similar case is

local foo do
    local bar = "bar"
    foo = bar
end

which I wished stylua puts the do in the same line of local foo.

haolian9 avatar Nov 24 '22 17:11 haolian9

This is an interesting suggestion.

For simplicity and consistency, I am somewhat hesitant about adding something like this in, but I will give it a think

Hi, i'd like to bump this because ever since the suggestion I've been wishing this was an addition. Could this be added as a configuration option so it's not intrusive for those who don't want it?

Aspecky avatar Apr 19 '23 13:04 Aspecky