Increase nesting in conditional expressions. Fix #122.
BUG=https://github.com/dart-lang/dart_style/issues/122
R=pquitslund@google.com
Review URL: https://chromiumcodereview.appspot.com//843653005
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8f1125..9e6e0c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
# 0.1.1-dev
* Support formatting enums (#120).
-* Handle Windows line endings in multiline strings (#126).
\ No newline at end of file
+* Handle Windows line endings in multiline strings (#126).
+* Increase nesting for conditional operators (#122).
\ No newline at end of file
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 0a228f7..93fc466 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -369,6 +369,7 @@
}
visitConditionalExpression(ConditionalExpression node) {
+ _writer.nestExpression();
visit(node.condition);
space();
@@ -387,6 +388,7 @@
_writer.endMultisplit();
_writer.endSpan();
+ _writer.unnest();
}
visitConstructorDeclaration(ConstructorDeclaration node) {
diff --git a/test/regression/122.unit b/test/regression/122.unit
new file mode 100644
index 0000000..b4a0794
--- /dev/null
+++ b/test/regression/122.unit
@@ -0,0 +1,26 @@
+>>>
+var xsrfValue = _urlIsSameOrigin(url) ?
+ _cookies[xsrfCookieName != null ?
+ xsrfCookieName :
+ defaults.xsrfCookieName] :
+ null;
+<<<
+var xsrfValue = _urlIsSameOrigin(url) ?
+ _cookies[xsrfCookieName != null ?
+ xsrfCookieName :
+ defaults.xsrfCookieName] :
+ null;
+>>>
+class _Streams {
+ _Streams(this._scope, this._exceptionHandler, _Streams inheritStreams)
+ : _typeCounts = inheritStreams == null ?
+ new HashMap<String, int>() :
+ new HashMap.from(inheritStreams._typeCounts);
+}
+<<<
+class _Streams {
+ _Streams(this._scope, this._exceptionHandler, _Streams inheritStreams)
+ : _typeCounts = inheritStreams == null ?
+ new HashMap<String, int>() :
+ new HashMap.from(inheritStreams._typeCounts);
+}
\ No newline at end of file
diff --git a/test/splitting/expressions.stmt b/test/splitting/expressions.stmt
index f034717..5564020 100644
--- a/test/splitting/expressions.stmt
+++ b/test/splitting/expressions.stmt
@@ -93,4 +93,14 @@
(identifier *
(verylongIdentifier *
verylongIdentifier) *
- identifier);
\ No newline at end of file
+ identifier);
+>>> conditional operands are nested
+identifier ? identifier ? someParticularlyLongOperand : someParticularlyLongOperand : identifier ? someParticularlyLongOperand : someParticularlyLongOperand;
+<<<
+identifier ?
+ identifier ?
+ someParticularlyLongOperand :
+ someParticularlyLongOperand :
+ identifier ?
+ someParticularlyLongOperand :
+ someParticularlyLongOperand;
\ No newline at end of file