@@ -57,6 +57,30 @@ void f(Future<void> f, Future<void>? g) async {
5757''' );
5858 }
5959
60+ test_awaitInside_methodInvocation () async {
61+ await assertNoDiagnostics (r'''
62+ void f(Future<int> f) async {
63+ (await f).toString();
64+ }
65+ ''' );
66+ }
67+
68+ test_awaitInside_prefixExpression () async {
69+ await assertNoDiagnostics (r'''
70+ void f(Future<bool> p) async {
71+ !(await p);
72+ }
73+ ''' );
74+ }
75+
76+ test_binaryExpressionInside_asExpression () async {
77+ await assertNoDiagnostics (r'''
78+ void f(int a, int b) {
79+ (b - a) as num;
80+ }
81+ ''' );
82+ }
83+
6084 test_binaryExpressionInside_constructorFieldInitializer () async {
6185 await assertDiagnostics (r'''
6286class C {
@@ -68,6 +92,14 @@ class C {
6892 ]);
6993 }
7094
95+ test_binaryExpressionInside_isExpression () async {
96+ await assertNoDiagnostics (r'''
97+ void f(num a, num b) {
98+ (b - a) is int;
99+ }
100+ ''' );
101+ }
102+
71103 test_binaryExpressionInside_namedArgument () async {
72104 await assertDiagnostics (r'''
73105void f({required int p}) {
@@ -114,6 +146,14 @@ bool f() {
114146 ]);
115147 }
116148
149+ test_binaryOperationInside_binaryOperation () async {
150+ await assertNoDiagnostics (r'''
151+ void f(bool a, bool b) {
152+ if ((a && b) || b) {}
153+ }
154+ ''' );
155+ }
156+
117157 /// https://github.com/dart-lang/linter/issues/4041
118158 test_cascadeAssignmentInside_nullAware () async {
119159 await assertNoDiagnostics (r'''
@@ -134,6 +174,28 @@ void g(List<int>? list) {
134174''' );
135175 }
136176
177+ test_cascadeInside_cascadeAssignmentExpression () async {
178+ await assertNoDiagnostics (r'''
179+ void f(A a, int x) {
180+ a..b = (x..isEven);
181+ }
182+ abstract class A {
183+ int b = 0;
184+ }
185+ ''' );
186+ }
187+
188+ test_cascadeInside_propertyAssignmentExpression () async {
189+ await assertNoDiagnostics (r'''
190+ void f(A a, int x) {
191+ a.b = (x..isEven);
192+ }
193+ abstract class A {
194+ int b = 0;
195+ }
196+ ''' );
197+ }
198+
137199 test_conditionalExpressionInside_argument () async {
138200 await assertDiagnostics (r'''
139201void f(int p) {
@@ -144,6 +206,12 @@ void f(int p) {
144206 ]);
145207 }
146208
209+ test_conditionalExpressionInside_expressionBody () async {
210+ await assertNoDiagnostics (r'''
211+ int f() => (1 == 1 ? 2 : 3);
212+ ''' );
213+ }
214+
147215 test_conditionalExpressionInside_listLiteral () async {
148216 await assertNoDiagnostics (r'''
149217void f() {
@@ -162,9 +230,11 @@ void f() {
162230 ]);
163231 }
164232
165- test_conditionalInside_expressionBody () async {
233+ test_conditionalExpressionInside_targetOfMethodInvocation () async {
166234 await assertNoDiagnostics (r'''
167- int f() => (1 == 1 ? 2 : 3);
235+ void f(bool b) {
236+ (b ? [] : [])..add('');
237+ }
168238''' );
169239 }
170240
@@ -387,6 +457,62 @@ bool f() {
387457''' );
388458 }
389459
460+ test_nullAwareCascadeInside_propretyAccess () async {
461+ await assertNoDiagnostics (r'''
462+ void f(int? a) {
463+ (a?..abs()).hashCode;
464+ }
465+ ''' );
466+ }
467+
468+ test_nullAwareIndexExpressionInside_postfixExpression () async {
469+ await assertNoDiagnostics (r'''
470+ void f(List<int?>? a) {
471+ (a?[0])!;
472+ }
473+ ''' );
474+ }
475+
476+ test_nullAwareIndexExpressionInside_propertyAccess () async {
477+ await assertNoDiagnostics (r'''
478+ void f(List<int>? a) {
479+ (a?[0]).hashCode;
480+ }
481+ ''' );
482+ }
483+
484+ test_nullAwareMethodInvocationInside_propertyAccess () async {
485+ await assertNoDiagnostics (r'''
486+ void f(int? a) {
487+ (a?.abs()).hashCode;
488+ }
489+ ''' );
490+ }
491+
492+ test_nullAwarePropertyAccessInside_postfixExpression () async {
493+ await assertNoDiagnostics (r'''
494+ void f(int? a) {
495+ (a?.sign)!;
496+ }
497+ ''' );
498+ }
499+
500+ test_nullAwarePropertyAccessInside_propertyAccess () async {
501+ await assertNoDiagnostics (r'''
502+ void f(int? a) {
503+ (a?.sign).hashCode;
504+ }
505+ ''' );
506+ }
507+
508+ test_nullCheckInside_conditionalExpressionCondition () async {
509+ await assertNoDiagnostics (r'''
510+ void f(bool? b) {
511+ (b ?? true) ? true : true;
512+ }
513+ ''' );
514+ }
515+
390516 @FailingTest (issue: 'https://github.com/dart-lang/linter/issues/4062' )
391517 test_parenthesizedPattern_nonPatternOutside () async {
392518 await assertDiagnostics (r'''
@@ -424,6 +550,37 @@ void f(int p) {
424550''' );
425551 }
426552
553+ test_prefixedIdentifierInside_cascadeAssignmentExpression () async {
554+ await assertNoDiagnostics (r'''
555+ void f(A a) {
556+ a..b = (a.b);
557+ }
558+ abstract class A {
559+ int b = 0;
560+ }
561+ ''' );
562+ }
563+
564+ test_prefixedIdentifierInside_targetOfMethodCall () async {
565+ await assertDiagnostics (r'''
566+ void f() {
567+ (0.isEven).toString();
568+ }
569+ ''' , [
570+ lint (13 , 10 ),
571+ ]);
572+ }
573+
574+ test_prefixedIdentifierInside_targetOfPropertyAccess () async {
575+ await assertDiagnostics (r'''
576+ void f() {
577+ (0.sign).isEven;
578+ }
579+ ''' , [
580+ lint (13 , 8 ),
581+ ]);
582+ }
583+
427584 test_prefixExpressionInside_targetOfMethodInvocation () async {
428585 await assertNoDiagnostics (r'''
429586void f(bool b) {
@@ -476,6 +633,114 @@ void g((int,) i) {}
476633 ]);
477634 }
478635
636+ test_setLiteralInside_binaryExpression () async {
637+ await assertNoDiagnostics (r'''
638+ void f() {
639+ ({1, 2, 3}) + {4};
640+ }
641+
642+ extension<T> on Set<T> {
643+ Set<T> operator +(Set<T> other) => {...this, ...other};
644+ }
645+ ''' );
646+ }
647+
648+ test_setLiteralInside_propertyAccess () async {
649+ await assertNoDiagnostics (r'''
650+ void f() {
651+ ({false, true}).length;
652+ }
653+ ''' );
654+ }
655+
656+ test_setLiteralInside_propertyAccess_functionArgument () async {
657+ await assertDiagnostics (r'''
658+ void f() {
659+ print(({1, 2, 3}).length);
660+ }
661+ ''' , [
662+ lint (19 , 11 ),
663+ ]);
664+ }
665+
666+ test_setLiteralInside_targetOfGenericTearoff () async {
667+ await assertNoDiagnostics (r'''
668+ void f() {
669+ ({1, 2, 3}).cast<num>;
670+ }
671+ ''' );
672+ }
673+
674+ test_simpleIdentifierInside_assignmentRightSide () async {
675+ await assertDiagnostics (r'''
676+ void f(int a) {
677+ a = (a);
678+ }
679+ ''' , [
680+ lint (22 , 3 ),
681+ ]);
682+ }
683+
684+ test_simpleIdentifierInside_conditionalExpressionCondition () async {
685+ await assertDiagnostics (r'''
686+ void f(bool a) {
687+ (a) ? 2 : 3;
688+ }
689+ ''' , [
690+ lint (19 , 3 ),
691+ ]);
692+ }
693+
694+ test_simpleIdentifierInside_conditionalExpressionElseExpression () async {
695+ await assertDiagnostics (r'''
696+ void f(int a) {
697+ 1 == 2 ? true : (a); // LINT
698+ }
699+ ''' , [
700+ lint (34 , 3 ),
701+ ]);
702+ }
703+
704+ test_simpleIdentifierInside_conditionalExpressionThenExpression () async {
705+ await assertDiagnostics (r'''
706+ void f(int a) {
707+ 1 == 2 ? (a) : false; // LINT
708+ }
709+ ''' , [
710+ lint (27 , 3 ),
711+ ]);
712+ }
713+
714+ test_simpleIdentifierInside_expressionStatement () async {
715+ await assertDiagnostics (r'''
716+ void f(int a) {
717+ (a);
718+ }
719+ ''' , [
720+ lint (18 , 3 ),
721+ ]);
722+ }
723+
724+ test_simpleIdentifierInside_functionArgument () async {
725+ await assertDiagnostics (r'''
726+ void f(int a) {
727+ print((a));
728+ }
729+ ''' , [
730+ lint (24 , 3 ),
731+ ]);
732+ }
733+
734+ test_simpleIdentifierInside_methodInvocation () async {
735+ await assertDiagnostics (r'''
736+ void f(Function fn) {
737+ (fn)(3);
738+ }
739+ ''' , [
740+ lint (24 , 4 ),
741+ ]);
742+ }
743+
479744 test_singleElementRecordWithNoTrailingCommaInside_assignment () async {
480745 await assertDiagnostics (r'''
481746void f() {
@@ -538,6 +803,38 @@ void f(Object? p) {
538803''' );
539804 }
540805
806+ test_startsWithConstInside_prefixExpression () async {
807+ await assertNoDiagnostics (r'''
808+ void f() {
809+ !(const [7].contains(42));
810+ }
811+ ''' );
812+ }
813+
814+ test_startsWithConstInside_targetOfMethodCall_prefixExpression () async {
815+ await assertNoDiagnostics (r'''
816+ void f() {
817+ !(const [7]).contains(42);
818+ }
819+ ''' );
820+ }
821+
822+ test_startsWithNew2Inside_prefixExpression () async {
823+ await assertNoDiagnostics (r'''
824+ void f() {
825+ -(new List.empty().length);
826+ }
827+ ''' );
828+ }
829+
830+ test_startsWithNewInside_prefixExpression () async {
831+ await assertNoDiagnostics (r'''
832+ void f() {
833+ !(new List.empty().contains(42));
834+ }
835+ ''' );
836+ }
837+
541838 test_stringLiteralInside () async {
542839 await assertDiagnostics (r'''
543840void f() {
@@ -622,6 +919,14 @@ extension on String? {
622919void f() {
623920 (List<int>).toString();
624921}
922+ ''' );
923+ }
924+
925+ test_typeLiteralInside_propertyAccess () async {
926+ await assertNoDiagnostics (r'''
927+ void f() {
928+ (String).hashCode;
929+ }
625930''' );
626931 }
627932}
0 commit comments