mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:28:02 +00:00
Do not apply the fix for avoid_function_literals_in_foreach_calls when body is not sync
Change-Id: I0482c0d35a01afffd26073383b137697b829249c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274943 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
c09f790d37
commit
2fbb93fc11
2 changed files with 69 additions and 0 deletions
|
@ -52,6 +52,9 @@ class ConvertForEachToForLoop extends CorrectionProducer {
|
|||
}
|
||||
var target = utils.getNodeText(invocation.target!);
|
||||
var body = argument.body;
|
||||
if (body.isAsynchronous || body.isGenerator) {
|
||||
return;
|
||||
}
|
||||
if (body is BlockFunctionBody) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addReplacement(range.startStart(invocation, body), (builder) {
|
||||
|
|
|
@ -129,6 +129,39 @@ void f(List<String> list) {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_blockBody_async() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
list.forEach((e) async {
|
||||
e.length / 2;
|
||||
});
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_blockBody_asyncStar() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
list.forEach((e) async* {
|
||||
e.length / 2;
|
||||
});
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_blockBody_syncStar() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
list.forEach((e) sync* {
|
||||
e.length / 2;
|
||||
});
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_expressionBody() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
|
@ -144,6 +177,39 @@ void f(List<String> list) {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_expressionBody_async() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
list.forEach((e) async => e.substring(3, 7));
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_expressionBody_asyncStar() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
list.forEach((e) async* => e.substring(3, 7));
|
||||
}
|
||||
''');
|
||||
await assertNoFix(
|
||||
errorFilter: (error) =>
|
||||
error.errorCode.name ==
|
||||
LintNames.avoid_function_literals_in_foreach_calls);
|
||||
}
|
||||
|
||||
Future<void> test_expressionBody_syncStar() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
list.forEach((e) sync* => e.substring(3, 7));
|
||||
}
|
||||
''');
|
||||
await assertNoFix(
|
||||
errorFilter: (error) =>
|
||||
error.errorCode.name ==
|
||||
LintNames.avoid_function_literals_in_foreach_calls);
|
||||
}
|
||||
|
||||
Future<void> test_return() async {
|
||||
await resolveTestCode('''
|
||||
void f(List<String> list) {
|
||||
|
|
Loading…
Reference in a new issue