From b989ccf733d627c15ec69652994c21db4d87671a Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 11 Aug 2020 15:23:49 +0000 Subject: [PATCH] bulk fix for `unawaited_futures` Change-Id: I0d53fe9d31b22a08585ea625a5dfbbf5ed5187e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158104 Reviewed-by: Brian Wilkerson Commit-Queue: Phil Quitslund --- .../correction/bulk_fix_processor.dart | 2 + .../correction/fix/bulk/add_await_test.dart | 41 +++++++++++++++++++ .../correction/fix/bulk/test_all.dart | 2 + 3 files changed, 45 insertions(+) create mode 100644 pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart index c0b1a6651a6..059880aa4c7 100644 --- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart +++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart @@ -8,6 +8,7 @@ import 'dart:core'; import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; import 'package:analysis_server/src/services/correction/change_workspace.dart'; import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart'; +import 'package:analysis_server/src/services/correction/dart/add_await.dart'; import 'package:analysis_server/src/services/correction/dart/add_override.dart'; import 'package:analysis_server/src/services/correction/dart/convert_add_all_to_spread.dart'; import 'package:analysis_server/src/services/correction/dart/convert_conditional_expression_to_if_element.dart'; @@ -88,6 +89,7 @@ class BulkFixProcessor { LintNames.prefer_spread_collections: ConvertAddAllToSpread.newInstance, LintNames.slash_for_doc_comments: ConvertDocumentationIntoLine.newInstance, LintNames.type_init_formals: RemoveTypeAnnotation.newInstance, + LintNames.unawaited_futures: AddAwait.newInstance, LintNames.unnecessary_const: RemoveUnnecessaryConst.newInstance, LintNames.unnecessary_lambdas: ReplaceWithTearOff.newInstance, LintNames.unnecessary_new: RemoveUnnecessaryNew.newInstance, diff --git a/pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart b/pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart new file mode 100644 index 00000000000..5ee8044c754 --- /dev/null +++ b/pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:analysis_server/src/services/linter/lint_names.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import 'bulk_fix_processor.dart'; + +void main() { + defineReflectiveSuite(() { + defineReflectiveTests(AddAwaitTest); + }); +} + +@reflectiveTest +class AddAwaitTest extends BulkFixProcessorTest { + @override + String get lintCode => LintNames.unawaited_futures; + + Future test_singleFile() async { + await resolveTestUnit(''' +Future doSomething() => new Future.value(''); +Future doSomethingElse() => new Future.value(''); + +void main() async { + doSomething(); + doSomethingElse(); +} +'''); + await assertHasFix(''' +Future doSomething() => new Future.value(''); +Future doSomethingElse() => new Future.value(''); + +void main() async { + await doSomething(); + await doSomethingElse(); +} +'''); + } +} diff --git a/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart index 8267b5dce2d..456f64d3a49 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart @@ -4,6 +4,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart'; +import 'add_await_test.dart' as add_await; import 'add_override_test.dart' as add_override; import 'convert_documentation_into_line_test.dart' as convert_documentation_into_line; @@ -41,6 +42,7 @@ import 'use_is_not_empty_test.dart' as use_is_not_empty; void main() { defineReflectiveSuite(() { + add_await.main(); add_override.main(); convert_documentation_into_line.main(); convert_to_contains.main();