[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: https://github.com/dart-lang/sdk/issues/60910 Bug: https://github.com/dart-lang/sdk/issues/60893 Change-Id: If088ad7e5ed1d2ed7f202a462baab5461ae046fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434541 Commit-Queue: Kallen Tu <kallentu@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
@@ -58,6 +58,18 @@ class A {
|
||||
);
|
||||
}
|
||||
|
||||
test_cascade_dotShorthand() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
f() {
|
||||
A a = .new()..x..x..x;
|
||||
}
|
||||
|
||||
class A {
|
||||
final x = 0;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_dot_shorthand() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
f() {
|
||||
@@ -77,6 +89,16 @@ f() {
|
||||
);
|
||||
}
|
||||
|
||||
test_forEach_inferredList_dotShorthands() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
enum E { a, b, c }
|
||||
|
||||
f() {
|
||||
for (E e in [.a, .b, .c]) { }
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_forEach_listWithNonObviousElement() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
f() {
|
||||
@@ -183,6 +205,16 @@ class A {}
|
||||
);
|
||||
}
|
||||
|
||||
test_instanceCreation_nonGeneric_dotShorthand() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
f() {
|
||||
A a = .new();
|
||||
}
|
||||
|
||||
class A {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_list() async {
|
||||
await assertDiagnostics(
|
||||
r'''
|
||||
@@ -194,6 +226,16 @@ f() {
|
||||
);
|
||||
}
|
||||
|
||||
test_list_dotShorthand() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
enum E { a, b, c }
|
||||
|
||||
f() {
|
||||
List<E> a = [.a, .b, .c];
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_list_ok1() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
f() {
|
||||
|
||||
@@ -203,6 +203,16 @@ class C {}
|
||||
);
|
||||
}
|
||||
|
||||
test_instanceCreation_nonGeneric_static_dotShorthand() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
class A {
|
||||
static C c = .new();
|
||||
}
|
||||
|
||||
class C {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_instanceCreation_nonGeneric_topLevel() async {
|
||||
await assertDiagnostics(
|
||||
r'''
|
||||
@@ -214,6 +224,14 @@ class C {}
|
||||
);
|
||||
}
|
||||
|
||||
test_instanceCreation_nonGeneric_topLevel_dotShorthand() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
C c = .new();
|
||||
|
||||
class C {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_list_ok1_static() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
class A {
|
||||
|
||||
Reference in New Issue
Block a user