handle trailing comma in asserts
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 62e0130..c3f1525 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -260,6 +260,15 @@
var arguments = <Expression>[node.condition];
if (node.message != null) arguments.add(node.message);
+ // If the argument list has a trailing comma, format it like a collection
+ // literal where each argument goes on its own line, they are indented +2,
+ // and the ")" ends up on its own line.
+ if (arguments.last.endToken.next.type == TokenType.COMMA) {
+ _visitCollectionLiteral(
+ null, node.leftParenthesis, arguments, node.rightParenthesis);
+ return;
+ }
+
builder.nestExpression();
var visitor = ArgumentListVisitor.forArguments(
this, node.leftParenthesis, node.rightParenthesis, arguments);
@@ -274,6 +283,15 @@
var arguments = [node.condition];
if (node.message != null) arguments.add(node.message);
+ // If the argument list has a trailing comma, format it like a collection
+ // literal where each argument goes on its own line, they are indented +2,
+ // and the ")" ends up on its own line.
+ if (arguments.last.endToken.next.type == TokenType.COMMA) {
+ _visitCollectionLiteral(
+ null, node.leftParenthesis, arguments, node.rightParenthesis);
+ return;
+ }
+
var visitor = ArgumentListVisitor.forArguments(
this, node.leftParenthesis, node.rightParenthesis, arguments);
visitor.visit();
diff --git a/test/splitting/constructors.unit b/test/splitting/constructors.unit
index 46948ad..ef790a3 100644
--- a/test/splitting/constructors.unit
+++ b/test/splitting/constructors.unit
@@ -107,6 +107,29 @@
argument),
argument));
}
+>>> split assert with trailing comma
+class Foo {
+ Foo() : assert(condition,);
+}
+<<<
+class Foo {
+ Foo()
+ : assert(
+ condition,
+ );
+}
+>>> split assert with trailing comma and message
+class Foo {
+ Foo() : assert(condition, "some message",);
+}
+<<<
+class Foo {
+ Foo()
+ : assert(
+ condition,
+ "some message",
+ );
+}
>>> trailing commas and initializer lists
class A {
A(a,):super();
diff --git a/test/splitting/statements.stmt b/test/splitting/statements.stmt
index 8d8d31c..13e9aea 100644
--- a/test/splitting/statements.stmt
+++ b/test/splitting/statements.stmt
@@ -28,6 +28,19 @@
assert(
veryVeryVeryVeryVeryLongCondition,
"long string that wraps");
+>>> split assert with trailing comma
+assert(condition,);
+<<<
+assert(
+ condition,
+);
+>>> split assert with trailing comma and message
+assert(condition, "some message",);
+<<<
+assert(
+ condition,
+ "some message",
+);
>>> split in do-while condition
do {} while ("some long string that wraps");
<<<