EmmyLuaCodeStyle
EmmyLuaCodeStyle copied to clipboard
Support aligning leading commas with leading { and (
Can an option to be added to support aligning commas with { and ( to enable this style:
local my_table =
{ foo
, bar
, baz
}
this is a very unusual style, is there any particular reason
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
I accept this reason, but it will take time to study
leading comma for '{' :
local t =
{ a = 123
, kjfolw = 123
, sjofjmwo = 123
}
for '(':
callll
( aaa
, bbb
, ccc
)
but what does '[' look like?
Good point - it doesn't apply in lua. I'll remove it from the title and original post.