-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: --fix-trailing-commas to always add trailing commas #753
Comments
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? |
Rather than decide on which ones, I'd be happy if |
That would be the most sensible option. The What's the status on this issue? |
I think the next step is for @munificent needs to triage. WDYT, @munificent? |
Anything related to trailing commas and the resultant formatting differences is a huge rathole that I don't have time to crawl into right now. Sorry. :( |
Hmm, I don't think the resultant formatting differences is related to this issue. I just thought you applied labels to issues as they came in, in a short triage process. Not a P1 from my perspective though. |
OK, labeled. :) |
😛 I'll take that as a "This seems like an acceptable idea. I'm open to pull requests 😁 " |
I'll take that as "I won't be offended if the PR languishes indefinitely." :) |
Well played, sir! |
Will this be implemented anytime soon? Formatting in Flutter looks way more consistent if I add , after long lists. |
It's unlikely to rise to the top of the priority list any time soon, unfortunately. |
Has the priority of this changed at all? The flutter docs recommend using trailing commas (see below). The docs say to use them, "at the end of a parameter list in functions, methods, and constructors where you care about keeping the formatting you crafted." The last part is subjective (and manual) and this leads to pretty significant inconsistencies in formatting throughout most flutter projects. Here is the full quote from the docs:
I think it is worth noting that other languages/formatters either support this as an option, or at least have proposals to support it. Some even make it the default. Here are some examples:
I think over the past few years this has started to become the norm as there are many compelling reasons to enforce trailing commas (formatting consistency, developer ergonomics, more meaningful diffs). |
Not yet, but I wouldn't be surprised if it did. I'm stretched pretty thin right now, but I would like to put some time into dartfmt if I can find it. |
this feature would be great |
Any updates here? I want this 😛 |
adding to the request impetus.. please.. pretty please!! |
I'd be willing to write a PR for this - is there any interest from the dev team about that? |
I definitely appreciate the offer, but I think any work here should be coordinated with a more holistic revisiting of how argument lists are formatted. Right now, the formatter does not assume most users want Flutter's style of argument formatting, so it would be very inconsistent if one of the Before dartfmt starts adding and/or removing trailing commas on your behalf, I'd like to reach consensus on what the preferred style around argument lists and trailing commas should be. That's a lot more social-level work than just a PR. The actual coding is the fun part. |
Hi, where can we find this social-level work ? it seems to be a rather consensual topic among other languages and i'm interested in this formatting for me and my team, so it would be cool to at least read want the defenders of "no-trailing comma" think on it. Thanks |
It hasn't started. It's going to be a time-consuming process and we haven't carved out the time for it yet. |
Any updates? |
No update yet, but I'm hoping to be able to put some time into it soon. |
Proposal at #1253 |
I'm going to close this out now since it's superseded by #1253. :) |
Motivation
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:
The Component constructor calls are semantically exactly the same. The CST differences:
]
positioned at column 0.templateUrl
, which is not given a List literal, has been listed out-of-alphabetical-order, as the second argument. The result is]
positioned at column 2, and each argument starting on its own line.]
positioned at column 4, with each argument starting on its own line.OK, I get it, the trailing comma situation results in different code. I don't want to address that here.
The ask
What I want is a
--fix
feature, like--fix-trailing-commas
, which adds trailing commas to list literals and function calls which are already being split into multiple lines. For example I would not want a trailing comma added toprint('hi')
, or to the single-linedProvider()
above.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...)
The text was updated successfully, but these errors were encountered: