From 104f2dff4e22ba098e6f165ba299f7f90aa1e1e6 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Tue, 23 Nov 2021 23:28:38 +0300 Subject: [PATCH 1/8] fix: prefer conditional expressions rule breaks code with increment / decrement operators --- CHANGELOG.md | 4 ++ .../prefer_conditional_expressions_rule.dart | 21 +++++- .../examples/example.dart | 24 +++++++ ...fer_conditional_expressions_rule_test.dart | 68 +++++++++++++++++-- 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe67b683d..5b0b972e75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +* fix: prefer conditional expressions rule breaks code with increment / decrement operators + ## 4.7.0 * feat: add static code diagnostics `avoid-throw-in-catch-block`, `avoid-unnecessary-type-assertions`, `avoid-unnecessary-type-casts`, `avoid-missing-enum-constant-in-map` diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart index 96e5ef72b5..91f7b26b8b 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart @@ -1,6 +1,7 @@ // ignore_for_file: public_member_api_docs import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/ast/token.dart'; import 'package:analyzer/dart/ast/visitor.dart'; import 'package:meta/meta.dart'; @@ -72,7 +73,15 @@ class PreferConditionalExpressionsRule extends CommonRule { final firstExpression = thenStatement.rightHandSide; final secondExpression = elseStatement.rightHandSide; - return '$target = $condition ? $firstExpression : $secondExpression;'; + final thenStatementOperator = thenStatement.operator.type.stringValue; + final elseStatementOperator = elseStatement.operator.type.stringValue; + + return _isIncrementDecrementOperation( + thenStatementOperator, + elseStatementOperator, + ) + ? '$condition ? ${thenStatement.leftHandSide} $thenStatementOperator $firstExpression : ${thenStatement.leftHandSide} $elseStatementOperator $secondExpression;' + : '$target = $condition ? $firstExpression : $secondExpression;'; } if (thenStatement is ReturnStatement && elseStatement is ReturnStatement) { @@ -84,4 +93,14 @@ class PreferConditionalExpressionsRule extends CommonRule { return null; } + + bool _isIncrementDecrementOperation( + String? thenStatementOperator, + String? elseStatementOperator, + ) => + thenStatementOperator != elseStatementOperator && + (thenStatementOperator == TokenType.PLUS_EQ.stringValue || + thenStatementOperator == TokenType.MINUS_EQ.stringValue) && + (elseStatementOperator == TokenType.PLUS_EQ.stringValue || + elseStatementOperator == TokenType.MINUS_EQ.stringValue); } diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart index f244bad978..8e7eafa0c3 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart @@ -140,3 +140,27 @@ int anotherTestFunction() { a = 6; } } + +int newCase() { + final cond = false; + final delta = 1; + final value = 9; + // LINT + if (cond) { + value += delta; + } else { + value -= delta; + } + // LINT + if (cond) { + value -= delta; + } else { + value += delta; + } + //LINT + if (cond) { + value -= 2; + } else { + value += 5; + } +} diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart index d2f7c57f58..cb4660d95c 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart @@ -26,10 +26,46 @@ void main() { RuleTestHelper.verifyIssues( issues: issues, - startOffsets: [111, 289, 426, 490, 557, 616, 889, 1040], - startLines: [11, 30, 45, 51, 58, 64, 93, 109], - startColumns: [3, 3, 3, 3, 3, 3, 3, 3], - endOffsets: [161, 345, 476, 543, 602, 663, 930, 1087], + startOffsets: [ + 111, + 289, + 426, + 490, + 557, + 616, + 889, + 1040, + 1496, + 1575, + 1653, + ], + startLines: [ + 11, + 30, + 45, + 51, + 58, + 64, + 93, + 109, + 149, + 155, + 161, + ], + startColumns: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], + endOffsets: [ + 161, + 345, + 476, + 543, + 602, + 663, + 930, + 1087, + 1562, + 1641, + 1711, + ], locationTexts: [ 'if (a == 3) {\n' ' a = 2;\n' @@ -67,6 +103,21 @@ void main() { ' return 2;\n' ' else\n' ' return a;', + 'if (cond) {\n' + ' value += delta;\n' + ' } else {\n' + ' value -= delta;\n' + ' }', + 'if (cond) {\n' + ' value -= delta;\n' + ' } else {\n' + ' value += delta;\n' + ' }', + 'if (cond) {\n' + ' value -= 2;\n' + ' } else {\n' + ' value += 5;\n' + ' }', ], messages: [ 'Prefer conditional expression.', @@ -77,6 +128,9 @@ void main() { 'Prefer conditional expression.', 'Prefer conditional expression.', 'Prefer conditional expression.', + 'Prefer conditional expression.', + 'Prefer conditional expression.', + 'Prefer conditional expression.', ], replacements: [ 'a = a == 3 ? 2 : 3;', @@ -87,6 +141,9 @@ void main() { 'a = a == 12 ? 2 : 3;', 'a = a == 17 ? 2 : 3;', 'return a == 20 ? 2 : a;', + 'cond ? value += delta : value -= delta;', + 'cond ? value -= delta : value += delta;', + 'cond ? value -= 2 : value += 5;', ], replacementComments: [ 'Convert to conditional expression.', @@ -97,6 +154,9 @@ void main() { 'Convert to conditional expression.', 'Convert to conditional expression.', 'Convert to conditional expression.', + 'Convert to conditional expression.', + 'Convert to conditional expression.', + 'Convert to conditional expression.', ], ); }); From 1d60f05c8aabf3f327dd0b65141e39461e0c8250 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Wed, 24 Nov 2021 23:04:09 +0300 Subject: [PATCH 2/8] Added new operators --- .../prefer_conditional_expressions_rule.dart | 24 ++++++++++++++----- .../examples/example.dart | 6 +++++ ...fer_conditional_expressions_rule_test.dart | 13 +++++++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart index 91f7b26b8b..3885d7dc0e 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart @@ -97,10 +97,22 @@ class PreferConditionalExpressionsRule extends CommonRule { bool _isIncrementDecrementOperation( String? thenStatementOperator, String? elseStatementOperator, - ) => - thenStatementOperator != elseStatementOperator && - (thenStatementOperator == TokenType.PLUS_EQ.stringValue || - thenStatementOperator == TokenType.MINUS_EQ.stringValue) && - (elseStatementOperator == TokenType.PLUS_EQ.stringValue || - elseStatementOperator == TokenType.MINUS_EQ.stringValue); + ) { + final supportedSymbols = [ + TokenType.SLASH_EQ.stringValue, // /= + TokenType.STAR_EQ.stringValue, // *= + TokenType.PERCENT_EQ.stringValue, // %= + TokenType.GT_GT_GT_EQ.stringValue, // >>>= + TokenType.CARET_EQ.stringValue, // ^= + TokenType.PLUS_EQ.stringValue, // += + TokenType.LT_LT_EQ.stringValue, // <<= + TokenType.MINUS_EQ.stringValue, // -= + TokenType.GT_GT_EQ.stringValue, // >>= + TokenType.BAR_EQ.stringValue, // |= + TokenType.TILDE_SLASH_EQ.stringValue, // ~/= + ]; + + return supportedSymbols.contains(thenStatementOperator) && + supportedSymbols.contains(elseStatementOperator); + } } diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart index 8e7eafa0c3..25a7bb8c23 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart @@ -163,4 +163,10 @@ int newCase() { } else { value += 5; } + //LINT + if (cond) { + value *= 2; + } else { + value /= 5; + } } diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart index cb4660d95c..91b911277a 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart @@ -38,6 +38,7 @@ void main() { 1496, 1575, 1653, + 1723, ], startLines: [ 11, @@ -51,8 +52,9 @@ void main() { 149, 155, 161, + 167, ], - startColumns: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], + startColumns: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,3], endOffsets: [ 161, 345, @@ -65,6 +67,7 @@ void main() { 1562, 1641, 1711, + 1781, ], locationTexts: [ 'if (a == 3) {\n' @@ -118,6 +121,11 @@ void main() { ' } else {\n' ' value += 5;\n' ' }', + 'if (cond) {\n' + ' value *= 2;\n' + ' } else {\n' + ' value /= 5;\n' + ' }', ], messages: [ 'Prefer conditional expression.', @@ -131,6 +139,7 @@ void main() { 'Prefer conditional expression.', 'Prefer conditional expression.', 'Prefer conditional expression.', + 'Prefer conditional expression.', ], replacements: [ 'a = a == 3 ? 2 : 3;', @@ -144,6 +153,7 @@ void main() { 'cond ? value += delta : value -= delta;', 'cond ? value -= delta : value += delta;', 'cond ? value -= 2 : value += 5;', + 'cond ? value *= 2 : value /= 5;', ], replacementComments: [ 'Convert to conditional expression.', @@ -157,6 +167,7 @@ void main() { 'Convert to conditional expression.', 'Convert to conditional expression.', 'Convert to conditional expression.', + 'Convert to conditional expression.', ], ); }); From 89cc491cb935082f4e3d9fe15c567d809dfa0fc4 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Wed, 24 Nov 2021 23:08:31 +0300 Subject: [PATCH 3/8] formatted code --- .../prefer_conditional_expressions_rule_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart index 91b911277a..58f107121c 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart @@ -54,7 +54,7 @@ void main() { 161, 167, ], - startColumns: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,3], + startColumns: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], endOffsets: [ 161, 345, From 3054acd275028907d163c12366806fd9ff502dc6 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Thu, 25 Nov 2021 15:46:04 +0300 Subject: [PATCH 4/8] fix compare by type --- .../prefer_conditional_expressions_rule.dart | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart index 3885d7dc0e..b150669d12 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart @@ -73,14 +73,14 @@ class PreferConditionalExpressionsRule extends CommonRule { final firstExpression = thenStatement.rightHandSide; final secondExpression = elseStatement.rightHandSide; - final thenStatementOperator = thenStatement.operator.type.stringValue; - final elseStatementOperator = elseStatement.operator.type.stringValue; + final thenStatementOperator = thenStatement.operator.type; + final elseStatementOperator = elseStatement.operator.type; return _isIncrementDecrementOperation( thenStatementOperator, elseStatementOperator, ) - ? '$condition ? ${thenStatement.leftHandSide} $thenStatementOperator $firstExpression : ${thenStatement.leftHandSide} $elseStatementOperator $secondExpression;' + ? '$condition ? ${thenStatement.leftHandSide} ${thenStatementOperator.stringValue} $firstExpression : ${thenStatement.leftHandSide} ${elseStatementOperator.stringValue} $secondExpression;' : '$target = $condition ? $firstExpression : $secondExpression;'; } @@ -95,21 +95,21 @@ class PreferConditionalExpressionsRule extends CommonRule { } bool _isIncrementDecrementOperation( - String? thenStatementOperator, - String? elseStatementOperator, + TokenType? thenStatementOperator, + TokenType? elseStatementOperator, ) { final supportedSymbols = [ - TokenType.SLASH_EQ.stringValue, // /= - TokenType.STAR_EQ.stringValue, // *= - TokenType.PERCENT_EQ.stringValue, // %= - TokenType.GT_GT_GT_EQ.stringValue, // >>>= - TokenType.CARET_EQ.stringValue, // ^= - TokenType.PLUS_EQ.stringValue, // += - TokenType.LT_LT_EQ.stringValue, // <<= - TokenType.MINUS_EQ.stringValue, // -= - TokenType.GT_GT_EQ.stringValue, // >>= - TokenType.BAR_EQ.stringValue, // |= - TokenType.TILDE_SLASH_EQ.stringValue, // ~/= + TokenType.SLASH_EQ, // /= + TokenType.STAR_EQ, // *= + TokenType.PERCENT_EQ, // %= + TokenType.GT_GT_GT_EQ, // >>>= + TokenType.CARET_EQ, // ^= + TokenType.PLUS_EQ, // += + TokenType.LT_LT_EQ, // <<= + TokenType.MINUS_EQ, // -= + TokenType.GT_GT_EQ, // >>= + TokenType.BAR_EQ, // |= + TokenType.TILDE_SLASH_EQ, // ~/= ]; return supportedSymbols.contains(thenStatementOperator) && From 1c1d9e568386c4862b9fb931d8a609fc7b0afd50 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Thu, 25 Nov 2021 15:55:20 +0300 Subject: [PATCH 5/8] fix compare by type --- .../prefer_conditional_expressions_rule.dart | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart index b150669d12..3c35fca2d4 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart @@ -76,10 +76,10 @@ class PreferConditionalExpressionsRule extends CommonRule { final thenStatementOperator = thenStatement.operator.type; final elseStatementOperator = elseStatement.operator.type; - return _isIncrementDecrementOperation( - thenStatementOperator, - elseStatementOperator, - ) + return (thenStatementOperator.isAssignmentOperator && + thenStatementOperator != TokenType.EQ) && + (thenStatementOperator != TokenType.EQ && + elseStatementOperator.isAssignmentOperator) ? '$condition ? ${thenStatement.leftHandSide} ${thenStatementOperator.stringValue} $firstExpression : ${thenStatement.leftHandSide} ${elseStatementOperator.stringValue} $secondExpression;' : '$target = $condition ? $firstExpression : $secondExpression;'; } @@ -93,26 +93,4 @@ class PreferConditionalExpressionsRule extends CommonRule { return null; } - - bool _isIncrementDecrementOperation( - TokenType? thenStatementOperator, - TokenType? elseStatementOperator, - ) { - final supportedSymbols = [ - TokenType.SLASH_EQ, // /= - TokenType.STAR_EQ, // *= - TokenType.PERCENT_EQ, // %= - TokenType.GT_GT_GT_EQ, // >>>= - TokenType.CARET_EQ, // ^= - TokenType.PLUS_EQ, // += - TokenType.LT_LT_EQ, // <<= - TokenType.MINUS_EQ, // -= - TokenType.GT_GT_EQ, // >>= - TokenType.BAR_EQ, // |= - TokenType.TILDE_SLASH_EQ, // ~/= - ]; - - return supportedSymbols.contains(thenStatementOperator) && - supportedSymbols.contains(elseStatementOperator); - } } From 13f459bc31d2880be076132df4863cc3b8bae753 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Thu, 25 Nov 2021 16:02:41 +0300 Subject: [PATCH 6/8] fix compare by type --- .../prefer_conditional_expressions_rule.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart index 3c35fca2d4..e569262003 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart @@ -76,10 +76,8 @@ class PreferConditionalExpressionsRule extends CommonRule { final thenStatementOperator = thenStatement.operator.type; final elseStatementOperator = elseStatement.operator.type; - return (thenStatementOperator.isAssignmentOperator && - thenStatementOperator != TokenType.EQ) && - (thenStatementOperator != TokenType.EQ && - elseStatementOperator.isAssignmentOperator) + return _isAssignmentOperatorNotEq(thenStatementOperator) && + _isAssignmentOperatorNotEq(elseStatementOperator) ? '$condition ? ${thenStatement.leftHandSide} ${thenStatementOperator.stringValue} $firstExpression : ${thenStatement.leftHandSide} ${elseStatementOperator.stringValue} $secondExpression;' : '$target = $condition ? $firstExpression : $secondExpression;'; } @@ -93,4 +91,7 @@ class PreferConditionalExpressionsRule extends CommonRule { return null; } + + bool _isAssignmentOperatorNotEq(TokenType token) => + token.isAssignmentOperator && token != TokenType.EQ; } From 6ef96c2202ee70151814941c03560abf8fc90915 Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Thu, 25 Nov 2021 20:50:32 +0300 Subject: [PATCH 7/8] review changes --- .../prefer_conditional_expressions/examples/example.dart | 4 ++-- .../prefer_conditional_expressions_rule_test.dart | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart index 25a7bb8c23..91beb23004 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart @@ -157,13 +157,13 @@ int newCase() { } else { value += delta; } - //LINT + // LINT if (cond) { value -= 2; } else { value += 5; } - //LINT + // LINT if (cond) { value *= 2; } else { diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart index 58f107121c..e3e77a7c44 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart @@ -37,8 +37,8 @@ void main() { 1040, 1496, 1575, - 1653, - 1723, + 1654, + 1725, ], startLines: [ 11, @@ -66,8 +66,8 @@ void main() { 1087, 1562, 1641, - 1711, - 1781, + 1712, + 1783, ], locationTexts: [ 'if (a == 3) {\n' From 7d37de9718a6207dd15dc778b0b9d634231b211a Mon Sep 17 00:00:00 2001 From: Konoshenko Vlad Date: Thu, 25 Nov 2021 21:12:47 +0300 Subject: [PATCH 8/8] review changes --- .../examples/example.dart | 4 ++++ ...fer_conditional_expressions_rule_test.dart | 24 +++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart index 91beb23004..fd7bf84adb 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/examples/example.dart @@ -145,24 +145,28 @@ int newCase() { final cond = false; final delta = 1; final value = 9; + // LINT if (cond) { value += delta; } else { value -= delta; } + // LINT if (cond) { value -= delta; } else { value += delta; } + // LINT if (cond) { value -= 2; } else { value += 5; } + // LINT if (cond) { value *= 2; diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart index e3e77a7c44..302b1a11b6 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/prefer_conditional_expressions/prefer_conditional_expressions_rule_test.dart @@ -35,10 +35,10 @@ void main() { 616, 889, 1040, - 1496, - 1575, - 1654, - 1725, + 1497, + 1577, + 1657, + 1729, ], startLines: [ 11, @@ -49,10 +49,10 @@ void main() { 64, 93, 109, - 149, - 155, - 161, - 167, + 150, + 157, + 164, + 171, ], startColumns: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], endOffsets: [ @@ -64,10 +64,10 @@ void main() { 663, 930, 1087, - 1562, - 1641, - 1712, - 1783, + 1563, + 1643, + 1715, + 1787, ], locationTexts: [ 'if (a == 3) {\n'