File tree Expand file tree Collapse file tree 2 files changed +51
-2
lines changed
lib/src/services/correction/dart
test/src/services/correction/fix Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,12 @@ class ReplaceFinalWithConst extends ResolvedCorrectionProducer {
38
38
var initializer = variable.initializer;
39
39
if (initializer != null ) {
40
40
Token ? constToken;
41
- if (initializer is InstanceCreationExpression ) {
42
- constToken = initializer.keyword;
41
+ if (initializer
42
+ case InstanceCreationExpression (: var keyword) ||
43
+ DotShorthandConstructorInvocation (
44
+ constKeyword: Token ? keyword,
45
+ )) {
46
+ constToken = keyword;
43
47
} else if (initializer is TypedLiteral ) {
44
48
constToken = initializer.constKeyword;
45
49
}
Original file line number Diff line number Diff line change @@ -41,6 +41,51 @@ class ReplaceFinalWithConstTest extends FixProcessorLintTest {
41
41
@override
42
42
String get lintCode => LintNames .prefer_const_declarations;
43
43
44
+ Future <void > test_const_dotShorthand_multiple () async {
45
+ await resolveTestCode ('''
46
+ class A {
47
+ const A.named();
48
+ }
49
+ final A a1 = const .named(), a2 = const .named();
50
+ ''' );
51
+ await assertHasFix ('''
52
+ class A {
53
+ const A.named();
54
+ }
55
+ const A a1 = .named(), a2 = .named();
56
+ ''' );
57
+ }
58
+
59
+ Future <void > test_const_dotShorthand_named () async {
60
+ await resolveTestCode ('''
61
+ class A {
62
+ const A.named();
63
+ }
64
+ final A a = const .named();
65
+ ''' );
66
+ await assertHasFix ('''
67
+ class A {
68
+ const A.named();
69
+ }
70
+ const A a = .named();
71
+ ''' );
72
+ }
73
+
74
+ Future <void > test_const_dotShorthand_unnamed () async {
75
+ await resolveTestCode ('''
76
+ class A {
77
+ const A();
78
+ }
79
+ final A a = const .new();
80
+ ''' );
81
+ await assertHasFix ('''
82
+ class A {
83
+ const A();
84
+ }
85
+ const A a = .new();
86
+ ''' );
87
+ }
88
+
44
89
Future <void > test_const_instanceCreation () async {
45
90
await resolveTestCode ('''
46
91
class A {
You can’t perform that action at this time.
0 commit comments