Skip to content

Commit 41eea71

Browse files
Dan Rubelcommit-bot@chromium.org
Dan Rubel
authored andcommitted
improve dartfix fix descriptions and add examples
Change-Id: I19c74bd9c55da29460ebe6f41b79e327429d6b22 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105323 Reviewed-by: Devon Carew <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
1 parent ea60ef9 commit 41eea71

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

pkg/analysis_server/lib/src/edit/fix/dartfix_info.dart

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,94 @@ import 'package:analysis_server/src/edit/fix/prefer_spread_collections_fix.dart'
1616

1717
const allFixes = <DartFixInfo>[
1818
//
19-
// Required fixes
19+
// Fixes enabled by default
2020
//
2121
const DartFixInfo(
2222
'fix-named-constructor-type-arguments',
23-
'Move named constructor type arguments from the name to the type.',
23+
'''
24+
Move named constructor type arguments from the name to the type.
25+
26+
For example, this
27+
new List.filled<String>(20, 'value');
28+
29+
will be converted to
30+
new List<String>.filled(20, 'value');''',
2431
FixErrorTask.fixNamedConstructorTypeArgs,
2532
isRequired: true,
2633
),
2734
const DartFixInfo(
2835
'use-mixin',
29-
'Convert classes used as a mixin to the new mixin syntax.',
36+
'''
37+
Convert classes used as a mixin to the new mixin syntax.
38+
39+
For example, this
40+
class C with M { }
41+
class M { }
42+
43+
will be converted to
44+
class C with M { }
45+
mixin M { }
46+
47+
There are several situations where a class cannot be automatically converted
48+
to a mixin such as when the class contains a constructor. In that situation
49+
a message is displayed and the class is not converted to a mixin.''',
3050
PreferMixinFix.task,
3151
isRequired: true,
3252
),
3353
//
34-
// Suggested fixes
54+
// Fixes that may be explicitly enabled
3555
//
3656
const DartFixInfo(
3757
'double-to-int',
38-
'Find double literals ending in .0 and remove the .0 '
39-
'wherever double context can be inferred.',
58+
'''
59+
Find double literals ending in .0 and remove the .0
60+
wherever double context can be inferred.
61+
62+
For example, this
63+
const double myDouble = 8.0;
64+
65+
will be converted to
66+
const double myDouble = 8;''',
4067
PreferIntLiteralsFix.task,
4168
),
4269
const DartFixInfo(
4370
'use-spread-collections',
44-
'Convert to using collection spread operators.',
71+
'''
72+
Convert to using collection spread operators.
73+
74+
For example, this
75+
var l1 = ['b'];
76+
var l2 = ['a']..addAll(l1);
77+
78+
will be converted to
79+
var l1 = ['b'];
80+
var l2 = ['a', ...l1];''',
4581
PreferSpreadCollectionsFix.task,
4682
isDefault: false,
4783
),
4884
const DartFixInfo(
4985
'collection-if-elements',
50-
'Convert to using if elements when building collections.',
86+
'''
87+
Convert to using if elements when building collections.
88+
89+
For example, this
90+
f(bool b) => ['a', b ? 'c' : 'd', 'e'];
91+
92+
will be converted to
93+
f(bool b) => ['a', if (b) 'c' else 'd', 'e'];''',
5194
PreferIfElementsToConditionalExpressionsFix.task,
5295
isDefault: false,
5396
),
5497
const DartFixInfo(
5598
'map-for-elements',
56-
'Convert to for elements when building maps from iterables.',
99+
'''
100+
Convert to for elements when building maps from iterables.
101+
102+
For example, this
103+
Map<int, int>.fromIterable([1, 2, 3], key: (i) => i, value: (i) => i * 2)
104+
105+
will be converted to
106+
<int, int>{ for(int i in [1, 2, 3]) i : i * 2, }''',
57107
PreferForElementsToMapFromIterableFix.task,
58108
isDefault: false,
59109
),
@@ -64,8 +114,10 @@ const allFixes = <DartFixInfo>[
64114
'non-nullable',
65115
// TODO(danrubel) update description and make default/required
66116
// when NNBD fix is ready
67-
'Experimental: Update sources to be non-nullable by default.\n'
68-
'This requires the experimental non-nullable flag to be enabled.',
117+
'''
118+
EXPERIMENTAL: Update sources to be non-nullable by default.
119+
This requires the experimental non-nullable flag to be enabled
120+
when running the updated application.''',
69121
NonNullableFix.task,
70122
isDefault: false,
71123
),

0 commit comments

Comments
 (0)