Rule suggesting to add trailing comma after last enumerator

In C and C++, enumerators can have a trailing comma. The same can be said when initializing an array, but I’ll consider that a less important topic, for another time. Having these trailing commas is beneficial because when these are listed on separate lines, adding a new element can be performed without changing any existing lines.

enum Color
{
    Red,
    Blue // <- non-compliant, missing comma
};

enum Color
{
    Red,
    Blue, // <- compliant, comma
};

I suppose the same would be relevant for other languages as well.

Hi @torgeir.skogen,

I agree that adding this trailing comma can be interesting, I use it quite often. It also makes it easy to reorder the elements.

At the same time, the consequences of not doing it are not very dire, and this trailing comma is not something I’ve seen in many style guides, so I expect such a rule to be verbose.

I created a ticket for it, but we’ll have to decide if it should be part of the SonarWay profile or if it should be an explicit opt-in.