Skip to content

Commit e62699c

Browse files
pqCommit Queue
authored and
Commit Queue
committed
invalid_case_patterns fix
See: #49960 Change-Id: I5ada583d5353521fe863d639bbad85691ca953ee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281870 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent cbebeeb commit e62699c

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,9 +1813,7 @@ LintCode.implementation_imports:
18131813
LintCode.implicit_call_tearoffs:
18141814
status: hasFix
18151815
LintCode.invalid_case_patterns:
1816-
status: needsFix
1817-
notes: |-
1818-
https://github.com/dart-lang/sdk/issues/49960
1816+
status: hasFix
18191817
LintCode.invariant_booleans:
18201818
status: needsEvaluation
18211819
LintCode.iterable_contains_unrelated_type:

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ class FixProcessor extends BaseProcessor {
503503
LintNames.implicit_call_tearoffs: [
504504
AddExplicitCall.new,
505505
],
506+
LintNames.invalid_case_patterns: [
507+
AddConst.new,
508+
],
506509
LintNames.leading_newlines_in_multiline_strings: [
507510
AddLeadingNewlineToString.new,
508511
],

pkg/analysis_server/test/src/services/correction/fix/add_const_test.dart

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import 'fix_processor.dart';
1111

1212
void main() {
1313
defineReflectiveSuite(() {
14+
defineReflectiveTests(AddConst_InvalidCasePatternsTest);
15+
defineReflectiveTests(AddConst_InvalidCasePatternsBulkTest);
1416
defineReflectiveTests(AddConst_NonConstGenerativeEnumConstructorTest);
1517
defineReflectiveTests(AddConst_PatternExpressionMustBeValidConst);
1618
defineReflectiveTests(AddConst_PreferConstConstructorsInImmutablesBulkTest);
@@ -23,6 +25,134 @@ void main() {
2325
});
2426
}
2527

28+
@reflectiveTest
29+
class AddConst_InvalidCasePatternsBulkTest extends BulkFixProcessorTest {
30+
@override
31+
String get lintCode => LintNames.invalid_case_patterns;
32+
33+
Future<void> test_singleFile() async {
34+
await resolveTestCode(r'''
35+
//@dart=2.19
36+
class C {
37+
const C();
38+
}
39+
40+
void f(Object c) {
41+
switch (c) {
42+
case C():
43+
case [1, 2]:
44+
}
45+
}
46+
''');
47+
await assertHasFix(r'''
48+
//@dart=2.19
49+
class C {
50+
const C();
51+
}
52+
53+
void f(Object c) {
54+
switch (c) {
55+
case const C():
56+
case const [1, 2]:
57+
}
58+
}
59+
''');
60+
}
61+
}
62+
63+
@reflectiveTest
64+
class AddConst_InvalidCasePatternsTest extends FixProcessorLintTest {
65+
@override
66+
FixKind get kind => DartFixKind.ADD_CONST;
67+
68+
@override
69+
String get lintCode => LintNames.invalid_case_patterns;
70+
71+
Future<void> test_constructorCall() async {
72+
await resolveTestCode(r'''
73+
//@dart=2.19
74+
class C {
75+
const C();
76+
}
77+
78+
void f(Object c) {
79+
switch (c) {
80+
case C():
81+
}
82+
}
83+
''');
84+
await assertHasFix(r'''
85+
//@dart=2.19
86+
class C {
87+
const C();
88+
}
89+
90+
void f(Object c) {
91+
switch (c) {
92+
case const C():
93+
}
94+
}
95+
''');
96+
}
97+
98+
Future<void> test_listLiteral() async {
99+
await resolveTestCode(r'''
100+
//@dart=2.19
101+
void f(Object o) {
102+
switch (o) {
103+
case [1, 2]:
104+
}
105+
}
106+
''');
107+
await assertHasFix(r'''
108+
//@dart=2.19
109+
void f(Object o) {
110+
switch (o) {
111+
case const [1, 2]:
112+
}
113+
}
114+
''');
115+
}
116+
117+
Future<void> test_mapLiteral() async {
118+
await resolveTestCode(r'''
119+
//@dart=2.19
120+
void f(Object o) {
121+
switch (o) {
122+
case {'k': 'v'}:
123+
}
124+
}
125+
''');
126+
await assertHasFix(r'''
127+
//@dart=2.19
128+
void f(Object o) {
129+
switch (o) {
130+
case const {'k': 'v'}:
131+
}
132+
}
133+
''');
134+
}
135+
136+
Future<void> test_setLiteral() async {
137+
await resolveTestCode(r'''
138+
//@dart=2.19
139+
void f(Object o) {
140+
switch (o) {
141+
case {1}:
142+
}
143+
}
144+
''');
145+
await assertHasFix(r'''
146+
//@dart=2.19
147+
void f(Object o) {
148+
switch (o) {
149+
case const {1}:
150+
}
151+
}
152+
''');
153+
}
154+
}
155+
26156
@reflectiveTest
27157
class AddConst_NonConstGenerativeEnumConstructorTest extends FixProcessorTest {
28158
@override

0 commit comments

Comments
 (0)