Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Unified Diff: lib/src/source_visitor.dart

Issue 1493553002: Smarter splitting around named collection arguments. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/rule/argument.dart ('k') | test/regression/0100/0108.unit » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source_visitor.dart
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 79d3e86e5b91f6a72177f38f11cca60ca8349c30..1cdd0bea0adb767b73716102ef3ccb831223d778 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -837,7 +837,7 @@ class SourceVisitor implements AstVisitor {
}
if (optionalParams.isNotEmpty) {
- var namedRule = new NamedRule();
+ var namedRule = new NamedRule(null, 0, 0);
if (rule != null) rule.setNamedArgsRule(namedRule);
_metadataRules.last.bindNamedRule(namedRule);
@@ -847,8 +847,7 @@ class SourceVisitor implements AstVisitor {
// Make sure multi-line default values are indented.
builder.startBlockArgumentNesting();
- namedRule
- .beforeArguments(builder.split(space: requiredParams.isNotEmpty));
+ namedRule.beforeArgument(builder.split(space: requiredParams.isNotEmpty));
// "[" or "{" for optional parameters.
token(node.leftDelimiter);
@@ -858,7 +857,7 @@ class SourceVisitor implements AstVisitor {
// Write the trailing comma.
if (param != node.parameters.last) token(param.endToken.next);
- if (param != optionalParams.last) split();
+ if (param != optionalParams.last) namedRule.beforeArgument(split());
}
builder.endBlockArgumentNesting();
@@ -1204,7 +1203,16 @@ class SourceVisitor implements AstVisitor {
builder.nestExpression();
builder.startSpan();
visit(node.name);
- visit(node.expression, before: soloSplit);
+
+ // Don't allow a split between a name and a collection. Instead, we want
+ // the collection itself to split, or to split before the argument.
+ if (node.expression is ListLiteral || node.expression is MapLiteral) {
+ space();
+ } else {
+ soloSplit();
+ }
+
+ visit(node.expression);
builder.endSpan();
builder.unnest();
}
« no previous file with comments | « lib/src/rule/argument.dart ('k') | test/regression/0100/0108.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698