neovim.github.io
neovim.github.io copied to clipboard
style guide: Require trailing comma
Current style guide does not talk about trailing commas in array and struct braced initializer list format. The example shows that it should be omitted in struct initialization, but I think this is bad idea in struct initializers (except for one-line ones) and it is especially bad idea in array initializers. Reasoning is simple and known: should you append element to the list without the trailing comma you are forced make not only one addition (+n lines line after last array element), but also a change to the last line of the last array element.
Thus I would suggest the following addition to the style guide: require trailing comma always when closing brace is placed on the separate line and require absense of trailing comma when closing brace is placed on the same line as the last element in the initializer list. This change does not even go against the example in http://neovim.io/develop/style-guide.xml?showone=Braced_Initializer_Lists#Braced_Initializer_Lists.
:+1:
Sounds reasonable to me.
This change does not even go against the example in http://neovim.io/develop/style-guide.xml?showone=Braced_Initializer_Lists#Braced_Initializer_List
@ZyX-I Would this be a correct example?
struct my_struct m = { // Here, you could also break before {.
superlongvariablename1,
superlongvariablename2,
{ short, interior, list },
{ interiorwrappinglist,
interiorwrappinglist2 },
};
@justinmk Yes, though I would prefer to keep the current one and add additional (unless you want to also require };
on the separate line as long as opening {
is on the separate line from the first element):
struct my_super_struct m = {
superlongvariablename1,
{ short, interior, list },
};
struct my_list_struct m[] = {
{ varname, { short, interior, list } },
{ superlongvariablename,
{ short, interior, list2 } },
};
(note: added example of the array).
The existing example shows that
… = {
… };
is allowed, changing it hangs this information (you don’t know whether it is allowed or not).
Needlessly complicated, but sure. @justinmk: should we move this issue to the neovim repo if it's still relevant?
should be a quick addition to :help dev-style
, let's just close this when that is done
This is enforced by our auto-formatter now:
https://github.com/neovim/neovim/blob/4b5ef0ff0aacff2d763f13fe50f9c2e97ffafd17/src/uncrustify.cfg#L3200