@@ -152,6 +152,112 @@ void f(List<String> list) {
152
152
await assertNoFix ();
153
153
}
154
154
155
+ Future <void > test_blockBody_preferFinal () async {
156
+ createAnalysisOptionsFile (
157
+ lints: [
158
+ LintNames .avoid_function_literals_in_foreach_calls,
159
+ LintNames .prefer_final_in_for_each,
160
+ ],
161
+ );
162
+ await resolveTestCode ('''
163
+ void f(List<String> list) {
164
+ list.forEach((e) {
165
+ e.substring(3, 7);
166
+ });
167
+ }
168
+ ''' );
169
+ await assertHasFix ('''
170
+ void f(List<String> list) {
171
+ for (final e in list) {
172
+ e.substring(3, 7);
173
+ }
174
+ }
175
+ ''' );
176
+ }
177
+
178
+ Future <void > test_blockBody_preferFinal_specifyTypes () async {
179
+ createAnalysisOptionsFile (
180
+ lints: [
181
+ LintNames .avoid_function_literals_in_foreach_calls,
182
+ LintNames .prefer_final_in_for_each,
183
+ LintNames .always_specify_types,
184
+ ],
185
+ );
186
+ await resolveTestCode ('''
187
+ void f(List<String> list) {
188
+ list.forEach((e) {
189
+ e.substring(3, 7);
190
+ });
191
+ }
192
+ ''' );
193
+ await assertHasFix ('''
194
+ void f(List<String> list) {
195
+ for (final String e in list) {
196
+ e.substring(3, 7);
197
+ }
198
+ }
199
+ ''' ,
200
+ errorFilter: (error) =>
201
+ error.errorCode.name ==
202
+ LintNames .avoid_function_literals_in_foreach_calls);
203
+ }
204
+
205
+ Future <void > test_blockBody_specifyTypes () async {
206
+ createAnalysisOptionsFile (
207
+ lints: [
208
+ LintNames .avoid_function_literals_in_foreach_calls,
209
+ LintNames .always_specify_types,
210
+ ],
211
+ );
212
+ await resolveTestCode ('''
213
+ void f(List<String> list) {
214
+ list.forEach((e) {
215
+ e.substring(3, 7);
216
+ });
217
+ }
218
+ ''' );
219
+ await assertHasFix ('''
220
+ void f(List<String> list) {
221
+ for (String e in list) {
222
+ e.substring(3, 7);
223
+ }
224
+ }
225
+ ''' ,
226
+ errorFilter: (error) =>
227
+ error.errorCode.name ==
228
+ LintNames .avoid_function_literals_in_foreach_calls);
229
+ }
230
+
231
+ Future <void > test_blockBody_specifyTypes_prefixed () async {
232
+ createAnalysisOptionsFile (
233
+ lints: [
234
+ LintNames .avoid_function_literals_in_foreach_calls,
235
+ LintNames .always_specify_types,
236
+ ],
237
+ );
238
+ await resolveTestCode ('''
239
+ import 'dart:core' as core;
240
+
241
+ void f(core.List<core.Set<core.String>> list) {
242
+ list.forEach((e) {
243
+ e.map((s) => s.substring(3, 7));
244
+ });
245
+ }
246
+ ''' );
247
+ await assertHasFix ('''
248
+ import 'dart:core' as core;
249
+
250
+ void f(core.List<core.Set<core.String>> list) {
251
+ for (core.Set<core.String> e in list) {
252
+ e.map((s) => s.substring(3, 7));
253
+ }
254
+ }
255
+ ''' ,
256
+ errorFilter: (error) =>
257
+ error.errorCode.name ==
258
+ LintNames .avoid_function_literals_in_foreach_calls);
259
+ }
260
+
155
261
Future <void > test_blockBody_syncStar () async {
156
262
await resolveTestCode ('''
157
263
void f(List<String> list) {
@@ -199,6 +305,76 @@ void f(List<String> list) {
199
305
LintNames .avoid_function_literals_in_foreach_calls);
200
306
}
201
307
308
+ Future <void > test_expressionBody_preferFinal () async {
309
+ createAnalysisOptionsFile (
310
+ lints: [
311
+ LintNames .avoid_function_literals_in_foreach_calls,
312
+ LintNames .prefer_final_in_for_each,
313
+ ],
314
+ );
315
+ await resolveTestCode ('''
316
+ void f(List<String> list) {
317
+ list.forEach((e) => e.substring(3, 7));
318
+ }
319
+ ''' );
320
+ await assertHasFix ('''
321
+ void f(List<String> list) {
322
+ for (final e in list) {
323
+ e.substring(3, 7);
324
+ }
325
+ }
326
+ ''' );
327
+ }
328
+
329
+ Future <void > test_expressionBody_preferFinal_specifyTypes () async {
330
+ createAnalysisOptionsFile (
331
+ lints: [
332
+ LintNames .avoid_function_literals_in_foreach_calls,
333
+ LintNames .prefer_final_in_for_each,
334
+ LintNames .always_specify_types,
335
+ ],
336
+ );
337
+ await resolveTestCode ('''
338
+ void f(List<String> list) {
339
+ list.forEach((e) => e.substring(3, 7));
340
+ }
341
+ ''' );
342
+ await assertHasFix ('''
343
+ void f(List<String> list) {
344
+ for (final String e in list) {
345
+ e.substring(3, 7);
346
+ }
347
+ }
348
+ ''' ,
349
+ errorFilter: (error) =>
350
+ error.errorCode.name ==
351
+ LintNames .avoid_function_literals_in_foreach_calls);
352
+ }
353
+
354
+ Future <void > test_expressionBody_specifyTypes () async {
355
+ createAnalysisOptionsFile (
356
+ lints: [
357
+ LintNames .avoid_function_literals_in_foreach_calls,
358
+ LintNames .always_specify_types,
359
+ ],
360
+ );
361
+ await resolveTestCode ('''
362
+ void f(List<String> list) {
363
+ list.forEach((e) => e.substring(3, 7));
364
+ }
365
+ ''' );
366
+ await assertHasFix ('''
367
+ void f(List<String> list) {
368
+ for (String e in list) {
369
+ e.substring(3, 7);
370
+ }
371
+ }
372
+ ''' ,
373
+ errorFilter: (error) =>
374
+ error.errorCode.name ==
375
+ LintNames .avoid_function_literals_in_foreach_calls);
376
+ }
377
+
202
378
Future <void > test_expressionBody_syncStar () async {
203
379
await resolveTestCode ('''
204
380
void f(List<String> list) {
0 commit comments