-
Notifications
You must be signed in to change notification settings - Fork 62
Add support for trailing commas in Emitter #376
Conversation
|
I'm nervous about sending the signal that I would prefer if we err on the side of being opinionated over being configurable. If we think trailing commas is a better default I'd like to use it everywhere, rather than increase the API surface. WDYT @jakemac53 ? |
|
I guess one other area that may come up is that we explicitly don't want to add options to have output that conforms to style lints. I would not accept PRs that, for instance, have options to conform to prefer single or double quotes, or to sort members within a class in a certain order. |
I don't mind this idea. I thought there might be a question of breakage (internal goldens?) but if code_builder has some contract that we can change the textual content of the output code, then that's great.
Yeah my motivation here is 100% for the performance concerns in dart_style. I took the effort to make a distinction between 1-element lists and multiple-element lists to make the generated output bearable, for developers writing builders, and users ctrl-clicking into generated code. But if it comes up against a principle, I'm find just adding commas anywhere. |
|
Maybe it would be worth considering some recursive logic. If the single argument of an invocation itself uses trailing comma, then it should probably do as well... Compare: foo(bar(
takes,
a,
lot,
of,
arguments,
));to I much prefer the second... |
|
I am fine with just always using them, at least for argument lists and list/map/set literals? The place I really dislike the style is for parameter lists. |
|
I've updated the code to always consider adding trailing commas. Trailing commas are still only added if there are multiple elements in a list. I deleted the tests I added as I think everything is covered with existing tests. This feature still applies to parameter lists; let me know if it should not. |
I think it's fine, I will survive lol. Technically parameter lists could also get quite large, and bob also mentioned that if you have arrow body functions with a large expression, trailing commas in parameter lists will help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a CHANGELOG?
Yeah we have made changes to the specific output in the past - we consider a test on the specific content output to be opting in to needing updates. It will make the next package roll more annoying since we will have to atomically update any golden tests, but that's typically pretty manageable. |
|
Changelog added; thanks! |
The big change affecting all of the goldens is that we now add trailing commas. The motivation is that code with trailing commas can avoid pathological corners of the formatter, which can save entire seconds in generating some Dart source code. See details at: dart-archive/code_builder#376 - f635ab6e2776955d057cf75757905f73f76adbd9 Add support for trailing commas in Emitter (#376) by Sam Rawlins <srawlins@google.com> - e082adb3e01d619370e7ec14b5f8ae6ac8ecf903 Fix spelling in README.md (#360) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> - bed3ca90fb5a42b2b4c7fc93a8d73652a06d4314 Fix spelling in CHANGELOG.md (#361) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> PiperOrigin-RevId: 469597645
The big change affecting all of the goldens is that we now add trailing commas. The motivation is that code with trailing commas can avoid pathological corners of the formatter, which can save entire seconds in generating some Dart source code. See details at: dart-archive/code_builder#376 - f635ab6e2776955d057cf75757905f73f76adbd9 Add support for trailing commas in Emitter (#376) by Sam Rawlins <srawlins@google.com> - e082adb3e01d619370e7ec14b5f8ae6ac8ecf903 Fix spelling in README.md (#360) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> - bed3ca90fb5a42b2b4c7fc93a8d73652a06d4314 Fix spelling in CHANGELOG.md (#361) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> PiperOrigin-RevId: 469597645
The big change affecting all of the goldens is that we now add trailing commas. The motivation is that code with trailing commas can avoid pathological corners of the formatter, which can save entire seconds in generating some Dart source code. See details at: dart-archive/code_builder#376 - f635ab6e2776955d057cf75757905f73f76adbd9 Add support for trailing commas in Emitter (#376) by Sam Rawlins <srawlins@google.com> - e082adb3e01d619370e7ec14b5f8ae6ac8ecf903 Fix spelling in README.md (#360) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> - bed3ca90fb5a42b2b4c7fc93a8d73652a06d4314 Fix spelling in CHANGELOG.md (#361) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> PiperOrigin-RevId: 469597645
The big change affecting all of the goldens is that we now add trailing commas. The motivation is that code with trailing commas can avoid pathological corners of the formatter, which can save entire seconds in generating some Dart source code. See details at: dart-archive/code_builder#376 - f635ab6e2776955d057cf75757905f73f76adbd9 Add support for trailing commas in Emitter (#376) by Sam Rawlins <srawlins@google.com> - e082adb3e01d619370e7ec14b5f8ae6ac8ecf903 Fix spelling in README.md (#360) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> - bed3ca90fb5a42b2b4c7fc93a8d73652a06d4314 Fix spelling in CHANGELOG.md (#361) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> PiperOrigin-RevId: 469597645
The big change affecting all of the goldens is that we now add trailing commas. The motivation is that code with trailing commas can avoid pathological corners of the formatter, which can save entire seconds in generating some Dart source code. See details at: dart-archive/code_builder#376 - f635ab6e2776955d057cf75757905f73f76adbd9 Add support for trailing commas in Emitter (dart-lang/mockito#376) by Sam Rawlins <srawlins@google.com> - e082adb3e01d619370e7ec14b5f8ae6ac8ecf903 Fix spelling in README.md (dart-lang/mockito#360) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> - bed3ca90fb5a42b2b4c7fc93a8d73652a06d4314 Fix spelling in CHANGELOG.md (dart-lang/mockito#361) by Saint Gabriel <53136855+chineduG@users.noreply.github.com> PiperOrigin-RevId: 469597645
Fixes dart-lang/tools#990
This adds trailing commas in various places according to the following rules:
The last one was certainly the most complex, because of the optional/named delimiters (
[]/{}).]or}).