Merge pull request #1019 from dart-lang/undo-flatten-conditionals
Revert the change to flatten nested conditionals.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0072f54..51ce9e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,6 @@
* Support triple-shift `>>>` and `>>>=` operators (#992).
* Support non-function type aliases (#993).
-* Less indentation on nested `?:` (#713, #722).
* Correct constructor initializer indentation after `required` (#1010).
# 2.0.0
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index b075062..7ad10c9 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -821,10 +821,14 @@
@override
void visitConditionalExpression(ConditionalExpression node) {
+ // TODO(rnystrom): Consider revisiting whether users prefer this after 2.13.
+ /*
// Flatten else-if style chained conditionals.
var shouldNest = node.parent is! ConditionalExpression ||
(node.parent as ConditionalExpression).elseExpression != node;
if (shouldNest) builder.nestExpression();
+ */
+ builder.nestExpression();
// Start lazily so we don't force the operator to split if a line comment
// appears before the first operand. If we split after one clause in a
@@ -859,7 +863,12 @@
builder.endRule();
builder.endSpan();
builder.endBlockArgumentNesting();
+
+ // TODO(rnystrom): Consider revisiting whether users prefer this after 2.13.
+ /*
if (shouldNest) builder.unnest();
+ */
+ builder.unnest();
}
@override
diff --git a/test/regression/0400/0407.unit b/test/regression/0400/0407.unit
index f783054..ffeb0d6 100644
--- a/test/regression/0400/0407.unit
+++ b/test/regression/0400/0407.unit
@@ -27,8 +27,9 @@
..formattedTotal = _total == 0
? ""
: _chartType == "PieChart"
- ? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
- : _formatter.formatValue(item.value, item.valueType);
+ ? _formatter.formatAsPercent(item.value / _total,
+ fractionDigits: 1)
+ : _formatter.formatValue(item.value, item.valueType);
}
>>> (indent 6)
main() {
@@ -36,8 +37,8 @@
..formattedTotal = _total == 0
? ""
: _chartType == "PieChart"
- ? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
- : _formatter.formatValue(item.value, item.valueType);
+ ? _formatter.formatAsPercent(item.value / _total, fractionDigits: 1)
+ : _formatter.formatValue(item.value, item.valueType);
}
<<<
main() {
@@ -45,7 +46,7 @@
..formattedTotal = _total == 0
? ""
: _chartType == "PieChart"
- ? _formatter.formatAsPercent(item.value / _total,
- fractionDigits: 1)
- : _formatter.formatValue(item.value, item.valueType);
+ ? _formatter.formatAsPercent(item.value / _total,
+ fractionDigits: 1)
+ : _formatter.formatValue(item.value, item.valueType);
}
\ No newline at end of file
diff --git a/test/regression/0700/0713.stmt b/test/regression/0700/0713.stmt
index 4a47471..36b3d4f 100644
--- a/test/regression/0700/0713.stmt
+++ b/test/regression/0700/0713.stmt
@@ -6,7 +6,7 @@
String type = status == 'OK'
? 'notices'
: status == 'NO'
- ? 'warnings'
- : status == 'BAD'
- ? 'errors'
- : '';
\ No newline at end of file
+ ? 'warnings'
+ : status == 'BAD'
+ ? 'errors'
+ : '';
\ No newline at end of file
diff --git a/test/regression/0700/0722.stmt b/test/regression/0700/0722.stmt
index 2e3e477..012b678 100644
--- a/test/regression/0700/0722.stmt
+++ b/test/regression/0700/0722.stmt
@@ -20,15 +20,15 @@
child: project.locked
? Icon(Icons.lock)
: project.fav
- ? Icon(Icons.star)
- : project.taps == null
- ? Icon(Icons.notifications)
- : Text(
- suffixNumber(project.taps),
- textAlign: TextAlign.center,
- style: TextStyle(
- fontSize: 18.0,
- fontWeight: FontWeight.w600,
- ),
- ),
+ ? Icon(Icons.star)
+ : project.taps == null
+ ? Icon(Icons.notifications)
+ : Text(
+ suffixNumber(project.taps),
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontSize: 18.0,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
);
\ No newline at end of file
diff --git a/test/regression/0900/0927.unit b/test/regression/0900/0927.unit
index 939d134..517df4f 100644
--- a/test/regression/0900/0927.unit
+++ b/test/regression/0900/0927.unit
@@ -7,6 +7,6 @@
int get currentAngleDigits => _currentSunAngleDeg < 0
? 1
: _currentSunAngleDeg < 10
- ? 2
- : 3;
+ ? 2
+ : 3;
}
\ No newline at end of file
diff --git a/test/splitting/expressions.stmt b/test/splitting/expressions.stmt
index 5bcd0d2..f6a666c 100644
--- a/test/splitting/expressions.stmt
+++ b/test/splitting/expressions.stmt
@@ -84,8 +84,8 @@
var kind = a
? b
: c
- ? d
- : e;
+ ? d
+ : e;
>>> don't split conditionals when indirectly nested
var kind = a ? b : (c ? d : e);
<<<
@@ -132,8 +132,8 @@
? someParticularlyLongOperand
: someParticularlyLongOperand
: identifier
- ? someParticularlyLongOperand
- : someParticularlyLongOperand;
+ ? someParticularlyLongOperand
+ : someParticularlyLongOperand;
>>> index expressions can split after "["
verylongIdentifier[someParticularlyLongArgument];
<<<