Skip to content

Commit

Permalink
Give record expressions block-like formatting in argument lists. (#1208)
Browse files Browse the repository at this point in the history
This is consistent with how other collection literals are formatted in
argument lists.

I originally made the formatting diverge deliberately because I felt
it would make it clearer when you're looking at a record versus a series
of arguments. But based on the thumbs up on:

#1205

It appears that users prefer the more consistent formatting. In
retrospect, I think I do too.
  • Loading branch information
munificent authored Apr 18, 2023
1 parent 80288ef commit 6c9bc10
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Don't format `sealed`, `interface`, and `final` keywords on mixin
declarations. The proposal was updated to no longer support them.
* Don't split before a single-section cascade following a record literal.
* Give records block-like formatting in argument lists (#1205).

# 2.3.0

Expand Down
1 change: 1 addition & 0 deletions lib/src/argument_list_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ class ArgumentSublist {
// TODO(rnystrom): Should we step into parenthesized expressions?

if (expression is ListLiteral) return expression.leftBracket;
if (expression is RecordLiteral) return expression.leftParenthesis;
if (expression is SetOrMapLiteral) return expression.leftBracket;
if (expression is SingleStringLiteral && expression.isMultiline) {
return expression.beginToken;
Expand Down
12 changes: 12 additions & 0 deletions test/regression/1200/1205.stmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
>>>
error(
offset: 10,
(
code: 'unclosed-block',
message: 'Block was left open',
));
<<<
error(offset: 10, (
code: 'unclosed-block',
message: 'Block was left open',
));
34 changes: 17 additions & 17 deletions test/splitting/records.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,27 @@ var record = (

element
);
>>> unlike collections, records do not do block-like formatting in arguments
>>> format like a block in an argument list
longFunctionName((element, element), (element, element, element, element));
<<<
longFunctionName(
(element, element),
(
element,
element,
element,
element
));
>>> unlike collections, records do not do block-like formatting in arguments
longFunctionName((
element,
element
), (
element,
element,
element,
element
));
>>> format like a block in an argument list
longFunctionName((element, element, element, element));
<<<
longFunctionName(
(
element,
element,
element,
element
));
longFunctionName((
element,
element,
element,
element
));
>>> don't allow splitting between field name and record
var record = (argument, argument, argument, recordFieldName: (veryLongElement__________,));
<<<
Expand Down

0 comments on commit 6c9bc10

Please sign in to comment.