Skip to content

Commit 01c542c

Browse files
srawlinsCommit Queue
authored andcommitted
lint rules: Move the last of the unnecessary_parenthesis tests
Change-Id: I0f26dffc3a49b10542fdbbf444572810998ff552 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393360 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 4096db4 commit 01c542c

File tree

2 files changed

+132
-62
lines changed

2 files changed

+132
-62
lines changed

pkg/linter/test/rules/unnecessary_parenthesis_test.dart

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ void f(int a, int b) {
8181
''');
8282
}
8383

84+
test_binaryExpressionInside_assignment() async {
85+
await assertNoDiagnostics(r'''
86+
void f(bool x) {
87+
x = (1 == 1);
88+
}
89+
''');
90+
}
91+
92+
test_binaryExpressionInside_binaryExpression() async {
93+
await assertNoDiagnostics(r'''
94+
void f() {
95+
(1 == 1) || "".isEmpty;
96+
97+
}
98+
''');
99+
}
100+
84101
test_binaryExpressionInside_constructorFieldInitializer() async {
85102
await assertDiagnostics(r'''
86103
class C {
@@ -146,6 +163,39 @@ bool f() {
146163
]);
147164
}
148165

166+
test_binaryExpressionInside_switchStatementVariable() async {
167+
await assertDiagnostics(r'''
168+
void f() {
169+
switch ((5 == 6)) {
170+
case true:
171+
return;
172+
default:
173+
return;
174+
}
175+
}
176+
''', [
177+
lint(21, 8),
178+
]);
179+
}
180+
181+
test_binaryExpressionInside_variableDeclarationInitializer() async {
182+
await assertNoDiagnostics(r'''
183+
void f() {
184+
var x = (1 == 1);
185+
}
186+
''');
187+
}
188+
189+
test_binaryExpressionInside_whileCondition() async {
190+
await assertDiagnostics(r'''
191+
void f() {
192+
while ((1 == 1)) {}
193+
}
194+
''', [
195+
lint(20, 8),
196+
]);
197+
}
198+
149199
test_binaryOperationInside_binaryOperation() async {
150200
await assertNoDiagnostics(r'''
151201
void f(bool a, bool b) {
@@ -206,12 +256,30 @@ void f(int p) {
206256
]);
207257
}
208258

259+
test_conditionalExpressionInside_argumentList() async {
260+
await assertNoDiagnostics(r'''
261+
void f() {
262+
'a'.substring((1 == 1 ? 2 : 3), 1);
263+
}
264+
''');
265+
}
266+
209267
test_conditionalExpressionInside_expressionBody() async {
210268
await assertNoDiagnostics(r'''
211269
int f() => (1 == 1 ? 2 : 3);
212270
''');
213271
}
214272

273+
test_conditionalExpressionInside_ifCondition() async {
274+
await assertDiagnostics(r'''
275+
void f() {
276+
if ((1 == 1 ? true : false)) {}
277+
}
278+
''', [
279+
lint(17, 23),
280+
]);
281+
}
282+
215283
test_conditionalExpressionInside_listLiteral() async {
216284
await assertNoDiagnostics(r'''
217285
void f() {
@@ -238,6 +306,14 @@ void f(bool b) {
238306
''');
239307
}
240308

309+
test_conditionalExpressionInside_variableDeclarationInitiailizer() async {
310+
await assertNoDiagnostics(r'''
311+
void f() {
312+
var x = (1 == 1 ? 2 : 3);
313+
}
314+
''');
315+
}
316+
241317
/// https://github.com/dart-lang/linter/issues/4060
242318
test_constantPattern() async {
243319
await assertNoDiagnostics(r'''
@@ -441,6 +517,16 @@ void f() {
441517
''');
442518
}
443519

520+
test_intLiteralInside_recordLiteral() async {
521+
await assertDiagnostics(r'''
522+
void f() {
523+
var x = (1, (2));
524+
}
525+
''', [
526+
lint(25, 3),
527+
]);
528+
}
529+
444530
test_listLiteral() async {
445531
await assertDiagnostics(r'''
446532
final items = [1, (DateTime.now())];
@@ -465,6 +551,22 @@ void f(int? a) {
465551
''');
466552
}
467553

554+
test_nullAwareIndexExpressionInside_conditionExpression() async {
555+
await assertNoDiagnostics(r'''
556+
void f(List<int>? a, bool b) {
557+
var x = b ? (a?[7]) : 7;
558+
}
559+
''');
560+
}
561+
562+
test_nullAwareIndexExpressionInside_mapLiteralKey() async {
563+
await assertNoDiagnostics(r'''
564+
void f(List<int>? a) {
565+
var x = {(a?[7]): 7};
566+
}
567+
''');
568+
}
569+
468570
test_nullAwareIndexExpressionInside_postfixExpression() async {
469571
await assertNoDiagnostics(r'''
470572
void f(List<int?>? a) {
@@ -561,6 +663,16 @@ abstract class A {
561663
''');
562664
}
563665

666+
test_prefixedIdentifierInside_recordLiteral() async {
667+
await assertDiagnostics(r'''
668+
void f() {
669+
var x = ((''.isEmpty), 2);
670+
}
671+
''', [
672+
lint(22, 12),
673+
]);
674+
}
675+
564676
test_prefixedIdentifierInside_targetOfMethodCall() async {
565677
await assertDiagnostics(r'''
566678
void f() {
@@ -589,6 +701,16 @@ void f(bool b) {
589701
''');
590702
}
591703

704+
test_propertyAccessInside_prefixExpression() async {
705+
await assertDiagnostics(r'''
706+
void f() {
707+
!([].isEmpty);
708+
}
709+
''', [
710+
lint(14, 12),
711+
]);
712+
}
713+
592714
test_propertyAccessInside_recordLiteral() async {
593715
await assertDiagnostics(r'''
594716
Record f() {
@@ -845,6 +967,16 @@ void f() {
845967
]);
846968
}
847969

970+
test_stringLiteralInside_variableDeclarationInitializer() async {
971+
await assertDiagnostics(r'''
972+
void f() {
973+
var x = ('');
974+
}
975+
''', [
976+
lint(21, 4),
977+
]);
978+
}
979+
848980
test_switchExpressionInside_argument() async {
849981
await assertDiagnostics(r'''
850982
void f(Object? x) {

pkg/linter/test_data/rules/unnecessary_parenthesis.dart

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)