Version Used: 15.5.5
Steps to Reproduce:
enum Some {
First,
Second
}
Expected Behavior:
I have an .editorconfig option to force developer to add comma after Second. It's useful, because it allows easy copy/paste and reordering member, and most important, when somebody else will add Third member, line with "Second" won't be changed and won't appear in comparsions.
Actual Behavior:
I have no way to force to add trailing comma.
P.S. Sorry for my English not being 100% sharp.
Is this still being considered? Was thinking about writing a rule to check for this, but if this is the right repo in which to implement this I'd be interested in submitting a PR here instead.
Additional context from @AArnott
There is a StyleCop.Analyzer that already does this:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1413.md
But it would be nice to add it to .editorconfig as well so that code generators can respect it.
Design review conclusion: it makes sense to add an editorconfig option to include this comma, which the various code generation features would then account for. We would also accept a pull request implementing an analyzer and code fix for this option, but the main item to implement first is the editorconfig option which is used by the syntax generator for code fixes and refactorings.
A year later, did this get anywhere?
@arch-stack this item has not been implemented so far. It's still up-for-grabs if someone in the community is available to contribute the implementation, but we don't currently have it scheduled to complete ourselves.
Looking at some examples of analyzers and code fixes you have, I'm interested. Seems the idea is to write an abstract base class that does the basic work, then pass in whatever language-specific tokenizers, etc., are needed. Though, in this case, after some doc lookups and experimentation, VB doesn't support trailing commas on enums (well, no commas anyway), collection initializers, or object initializers (the latter of which uses With anyway). So just a standalone class in C#?
Yes, this would only be needed/implemented for C#.
I'd be interested in trying to figure this out but it's a huge uphill learning experience for me. Wouldn't even know where to start
@arch-stack I'd recommnd starting with something smaller first just to get a hang of the basics of roslyn (i.e. enlisting, building, modifying, testing, pull-requests, etc). When comfortable there, moving to something like this would be a lot easier :)
@arch-stack this is a little more challenging than some of our "first time" fixes, but probably still can be done. I would expect the following sequence would be the most successful:
Once these three steps are done, we have the option of either merging the change as a first step and/or providing guidance on which feature(s) should be tackled next.
I've got a start on this but wondering if we want the granularity of separate options per enum, object initializer, and collection initializer. I'm assuming so for now since existing options (related or otherwise) are granular. Or just a single option like UseTrailingCommasInMultiLineInitializers?
With formatting options we generally separate out expressions versus declarations. So I would do the same here. Two options. One for trailing commas in expressions, one for declarations.
You could always just upgrade to rider and use dotsettings.
@CyrusNajmabadi it seems like only one option would be needed here. I don't think StyleCop Analyzers ever had a request to split the single option in two, and even if it did it would be an extreme minority scenario.