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

Unified Diff: lib/src/source_visitor.dart

Issue 1504553002: Better handling for binary operators in => bodies. (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 | « CHANGELOG.md ('k') | test/regression/0000/0005.stmt » ('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 1cdd0bea0adb767b73716102ef3ccb831223d778..38f148f7ff2ad2dcf6359c025ceea873746f78bc 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -185,7 +185,17 @@ class SourceVisitor implements AstVisitor {
visitBinaryExpression(BinaryExpression node) {
builder.startSpan();
- builder.nestExpression();
+
+ // If a binary operator sequence appears immediately after a `=>`, don't
+ // add an extra level of nesting. Instead, let the subsequent operands line
+ // up with the first, as in:
+ //
+ // method() =>
+ // argument &&
+ // argument &&
+ // argument;
+ var isArrowBody = node.parent is ExpressionFunctionBody;
+ if (!isArrowBody) builder.nestExpression();
// Start lazily so we don't force the operator to split if a line comment
// appears before the first operand.
@@ -217,7 +227,7 @@ class SourceVisitor implements AstVisitor {
builder.endBlockArgumentNesting();
- builder.unnest();
+ if (!isArrowBody) builder.unnest();
builder.endSpan();
builder.endRule();
}
@@ -709,7 +719,10 @@ class SourceVisitor implements AstVisitor {
// Split after the "=>", using the rule created before the parameters
// by _visitBody().
split();
- builder.endRule();
+
+ // If the body is a binary operator expression, then we want to force the
+ // split at `=>` if the operators split. See visitBinaryExpression().
+ if (node.expression is! BinaryExpression) builder.endRule();
if (_isInLambda(node)) builder.endSpan();
@@ -719,6 +732,8 @@ class SourceVisitor implements AstVisitor {
builder.endSpan();
builder.endBlockArgumentNesting();
+ if (node.expression is BinaryExpression) builder.endRule();
+
token(node.semicolon);
}
« no previous file with comments | « CHANGELOG.md ('k') | test/regression/0000/0005.stmt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698