Skip to content

Commit 26b2219

Browse files
kallentuCommit Queue
authored andcommitted
[linter] Dot shorthands: Add tests for omit_obvious_types.
Make sure that we're not suggesting to omit types for these two lints with dot shorthands, which shouldn't be the case since we didn't add extra logic for `hasObviousType`. Added a few tests. Fixes: #60910 Bug: #60893 Change-Id: If088ad7e5ed1d2ed7f202a462baab5461ae046fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434541 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 64a0903 commit 26b2219

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

pkg/linter/test/rules/omit_obvious_local_variable_types_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class A {
5858
);
5959
}
6060

61+
test_cascade_dotShorthand() async {
62+
await assertNoDiagnostics(r'''
63+
f() {
64+
A a = .new()..x..x..x;
65+
}
66+
67+
class A {
68+
final x = 0;
69+
}
70+
''');
71+
}
72+
6173
test_dot_shorthand() async {
6274
await assertNoDiagnostics(r'''
6375
f() {
@@ -77,6 +89,16 @@ f() {
7789
);
7890
}
7991

92+
test_forEach_inferredList_dotShorthands() async {
93+
await assertNoDiagnostics(r'''
94+
enum E { a, b, c }
95+
96+
f() {
97+
for (E e in [.a, .b, .c]) { }
98+
}
99+
''');
100+
}
101+
80102
test_forEach_listWithNonObviousElement() async {
81103
await assertNoDiagnostics(r'''
82104
f() {
@@ -183,6 +205,16 @@ class A {}
183205
);
184206
}
185207

208+
test_instanceCreation_nonGeneric_dotShorthand() async {
209+
await assertNoDiagnostics(r'''
210+
f() {
211+
A a = .new();
212+
}
213+
214+
class A {}
215+
''');
216+
}
217+
186218
test_list() async {
187219
await assertDiagnostics(
188220
r'''
@@ -194,6 +226,16 @@ f() {
194226
);
195227
}
196228

229+
test_list_dotShorthand() async {
230+
await assertNoDiagnostics(r'''
231+
enum E { a, b, c }
232+
233+
f() {
234+
List<E> a = [.a, .b, .c];
235+
}
236+
''');
237+
}
238+
197239
test_list_ok1() async {
198240
await assertNoDiagnostics(r'''
199241
f() {

pkg/linter/test/rules/omit_obvious_property_types_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ class C {}
203203
);
204204
}
205205

206+
test_instanceCreation_nonGeneric_static_dotShorthand() async {
207+
await assertNoDiagnostics(r'''
208+
class A {
209+
static C c = .new();
210+
}
211+
212+
class C {}
213+
''');
214+
}
215+
206216
test_instanceCreation_nonGeneric_topLevel() async {
207217
await assertDiagnostics(
208218
r'''
@@ -214,6 +224,14 @@ class C {}
214224
);
215225
}
216226

227+
test_instanceCreation_nonGeneric_topLevel_dotShorthand() async {
228+
await assertNoDiagnostics(r'''
229+
C c = .new();
230+
231+
class C {}
232+
''');
233+
}
234+
217235
test_list_ok1_static() async {
218236
await assertNoDiagnostics(r'''
219237
class A {

0 commit comments

Comments
 (0)