-
Notifications
You must be signed in to change notification settings - Fork 170
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
consider extending require_trailing_commas
to include record expressions
#3650
Comments
require_trailing_commas
to include record declarationsrequire_trailing_commas
to include record expressions
@munificent Do you expect that the formatter will treat trailing commas in records and record types similar to the way they're treated in other lists (that is, forcing each item to appear on a separate line)? Will that include single field records where the trailing comma is required? |
@munificent: any thoughts here on how the formatter will treat records? (Like lists?) (Formatter tracking issue: dart-lang/dart_style#1128.) |
Strangely, I haven't thought much about how records will be formatted. Yes, it will probably be like list literals. I think it's reasonable if this lint applies to record expressions (and record type annotations?) too. |
To be precise and not cross wires, |
It also currently flags function declarations, which are similar to record types. |
Note that the lint should not flag a record literal with a single element that has no trailing comma (even if it splits across lines) because that's already a compile time error and we don't want to double report the issue. |
Maybe can be done in same issue, maybe not, but just commenting: should also be added in RecordPatterns, ListPatterns, MapPatterns, and ObjectPatterns (similar to InstanceCreationExpressions). |
Circling back...
Yes, that's how the formatter formats them now, with the exception of records with only a single positional field. Those must have a trailing comma, but the trailing comma doesn't cause a split. So the formatter produces: var one = (1,);
var two = (
1,
2,
);
var oneNamed = (
name: 1,
);
By "compile time error" do you mean "perfectly valid parenthesized expression"?
If you really want to be exhaustive (because I have just run through this in my experimental Flutter-style branch of the formatter), the other one is It is a curious irregularity of the language that type parameter and type argument lists completely forbid trailing commas. |
Nope. It appears that I misspoke. I guess I should have said "warning". The analyzer currently produces a warning in this code:
I'm not sure why it's a warning. I thought it was a replacement for the compiler error "A value of type 'int' can't be assigned to a variable of type '(int)'.", where the replacement was done because the lexical difference between the types can be hard to see. That might be a bug. |
Yeah, that definitely seems wrong. There should be a compile error in that program. |
For example, should the following get flagged by
require_trailing_commas
?/fyi @lauweijie
The text was updated successfully, but these errors were encountered: