EmmyLuaCodeStyle icon indicating copy to clipboard operation
EmmyLuaCodeStyle copied to clipboard

Support aligning leading commas with leading { and (

Open ddickstein opened this issue 2 years ago • 5 comments
trafficstars

Can an option to be added to support aligning commas with { and ( to enable this style:

local my_table =
  { foo
  , bar
  , baz
  }

ddickstein avatar Dec 24 '22 19:12 ddickstein

this is a very unusual style, is there any particular reason

CppCXY avatar Dec 25 '22 04:12 CppCXY

I grant that it's uncommon. I think it's a style that tends to be more favored in languages that do not allow trailing commas because it removes the friction of editing the end of the list of fields (at the cost of adding friction when editing the start of the list). I think the argument for supporting it in Lua is mostly for trying to keep similar styles across a multi-lingual codebase where the comma-leading style has been adopted in other places. For example, in a Neovim codebase you might have Vimscript and Lua mixed, and the reason you might adopt a leading comma style in Vimscript is that the \ for continuing on the next line is placed in the leading position, so it more naturally lends itself to something like:

let x =
  \{ 'key1': value1
  \, 'key2': value2
  \}

The other arguable benefit of a leading-comma style is that it keeps the logic on the left and the data on the right - similar to the reason you might want to break up a long if long_condition_1 and long_condition_2 then ... end as

if long_condition_1
and long_condition_2
then
  ...
end

ddickstein avatar Dec 25 '22 17:12 ddickstein

I accept this reason, but it will take time to study

CppCXY avatar Dec 26 '22 03:12 CppCXY

leading comma for '{' :

local t =
    { a = 123
    , kjfolw = 123
    , sjofjmwo = 123
    }

for '(':

callll
    ( aaa
    , bbb
    , ccc
    )

but what does '[' look like?

CppCXY avatar Jan 16 '23 11:01 CppCXY

Good point - it doesn't apply in lua. I'll remove it from the title and original post.

ddickstein avatar Jan 16 '23 22:01 ddickstein