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

Unified Diff: lib/src/source_visitor.dart

Issue 1191833002: Split after "=>" if the parameters split. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 6 months 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 | « CHANGELOG.md ('k') | test/regression/108.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 3d028cec9f67d57a9dfc448d6662ff40b0317d32..2ad1df12d0c96c407eb9156eb6a0167e711a4881 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -718,7 +718,11 @@ class SourceVisitor implements AstVisitor {
if (_isInLambda(node)) builder.startSpan();
token(node.functionDefinition); // "=>".
- soloSplit(Cost.arrow);
+
+ // Split after the "=>", using the rule created before the parameters
+ // by _visitBody().
+ split();
+ builder.endRule();
if (_isInLambda(node)) builder.endSpan();
@@ -1567,13 +1571,34 @@ class SourceVisitor implements AstVisitor {
void _visitBody(FormalParameterList parameters, FunctionBody body,
[afterParameters()]) {
// If the body is "=>", add an extra level of indentation around the
- // parameters and the body. This ensures that if the parameters wrap, they
- // wrap more deeply than the "=>" does, as in:
+ // parameters and a rule that spans the parameters and the "=>". This
+ // ensures that if the parameters wrap, they wrap more deeply than the "=>"
+ // does, as in:
//
// someFunction(parameter,
// parameter, parameter) =>
// "the body";
- if (body is ExpressionFunctionBody) builder.nestExpression();
+ //
+ // Also, it ensures that if the parameters wrap, we split at the "=>" too
+ // to avoid:
+ //
+ // someFunction(parameter,
+ // parameter) => function(
+ // argument);
+ //
+ // This is confusing because it looks like those two lines are at the same
+ // level when they are actually unrelated. Splitting at "=>" forces:
+ //
+ // someFunction(parameter,
+ // parameter) =>
+ // function(
+ // argument);
+ if (body is ExpressionFunctionBody) {
+ builder.nestExpression();
+
+ // This rule is ended by visitExpressionFunctionBody().
+ builder.startRule(new SimpleRule(cost: Cost.arrow));
+ }
if (parameters != null) {
builder.nestExpression();
« no previous file with comments | « CHANGELOG.md ('k') | test/regression/108.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698