Skip to content

Commit

Permalink
Format assignment expressions. (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
munificent authored Oct 24, 2023
1 parent f043022 commit c5d20ba
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class AstNodeVisitor extends ThrowingAstVisitor<void>

@override
void visitAssignmentExpression(AssignmentExpression node) {
throw UnimplementedError();
visit(node.leftHandSide);
writer.space();
finishAssignment(node.operator, node.rightHandSide);
}

@override
Expand Down
68 changes: 68 additions & 0 deletions test/expression/assignment.stmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
40 columns |
>>> Chained assignment.
a=b=c;
<<<
a = b = c;
>>> Compound assignment operators.
a*=b/=c~/=d%=e;
<<<
a *= b /= c ~/= d %= e;
>>>
a+=b-=c;
<<<
a += b -= c;
>>>
a<<=b>>>=c>>=d;
<<<
a <<= b >>>= c >>= d;
>>>
a&=b^=c|=d;
<<<
a &= b ^= c |= d;
>>>
a??=b;
<<<
a ??= b;
>>> Split after `=`.
variableName = thisIsReallyQuiteAVeryLongVariableName;
<<<
variableName =
thisIsReallyQuiteAVeryLongVariableName;
>>> Prefer to split at "=" over infix operator.
variableName = argument * argument + argument;
<<<
variableName =
argument * argument + argument;
>>> Prefer block-like splitting for collections.
variableName = [element, element, element];
<<<
variableName = [
element,
element,
element,
];
>>> Prefer block-like splitting for function calls.
variableName = function(argument, argument);
<<<
variableName = function(
argument,
argument,
);
>>> No block-like splitting for empty argument lists.
variableNameExactLength____ = function();
<<<
variableNameExactLength____ =
function();
>>> No block-like splitting if function name doesn't fit.
longVariableName = veryLongFunctionName_(argument);
<<<
longVariableName =
veryLongFunctionName_(argument);
>>> Indent block if function name doesn't fit and arguments split.
longVariableName = veryLongFunctionName_(argument, another);
<<<
longVariableName =
veryLongFunctionName_(
argument,
another,
);

0 comments on commit c5d20ba

Please sign in to comment.