Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
FR: --fix-trailing-commas to always add trailing commas #753
Large function calls (e.g. constructors), such as the large annotation calls in Angular, can be formatted 3 (three) (un, deux, trois) ways, based on the commas:
@Component(selector: 'button', templateUrl: 'button.html', directives: [ ItemOne, NoTrailingComma ], providers: [ providerOne, Provider(FooBuilder, useFactory: provideFooBuilder) ], exports: [ ExportOne, ExportTwo ]) int a; @Component( selector: 'button', directives: [ ItemOne, TrailingComma, ], providers: [ providerOne, Provider(FooBuilder, useFactory: provideFooBuilder), ], exports: [ ExportOne, ExportTwo, ], templateUrl: 'button.html', ) int b; @Component( selector: 'button', directives: [ ItemOne, TrailingComma, ], providers: [ providerOne, Provider(FooBuilder, useFactory: provideFooBuilder), ], exports: [ ExportOne, ExportTwo, ], templateUrl: 'button.html') int c;
The Component constructor calls are semantically exactly the same. The CST differences:
OK, I get it, the trailing comma situation results in different code. I don't want to address that here.
What I want is a
The goal is to unify all long method calls and list literals to the second case above, which I think today is most common anyway, and is the most visually appealing.
And actually, in my example I've severely trimmed the list of directives and such. The code I took this from had a dozen or so directives, so it was always going to be multiple lines.
(Also Map literals and Set literals I imagine...)
What about method signatures at the definition point? They also allow trailing commas that impact formatting? Further complicated by optional positional or named arguments...
I agree that making the edits manually and keeping things consistent within a project is tough now and could be automated. What I worry about is whether this is opening dartfmt up for too much configurability and style arguments - there are at least 3 situations where this could be applied - signatures, collection literals, function calls - who decides which of the 3 get it?
That would be the most sensible option. The
What's the status on this issue?