From 3972ab221368396707bdc9dd0b62bb9f53b8b2c9 Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 21 May 2024 23:44:58 +0000 Subject: [PATCH 1/2] quick fix for `unnecessary_await_in_return` Change-Id: I30b0e48d7c5b93766580d23b35d7e2a6c8c9a44b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367341 Commit-Queue: Phil Quitslund Reviewed-by: Brian Wilkerson --- .../services/correction/error_fix_status.yaml | 4 +- .../src/services/correction/fix_internal.dart | 3 ++ .../lib/src/services/linter/lint_names.dart | 2 + .../correction/fix/remove_await_test.dart | 44 +++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index 0ee0d3717ab3..29483e544eca 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -2393,9 +2393,7 @@ LintCode.unintended_html_in_doc_comment: notes: |- The fix is to encode the angle brackets. LintCode.unnecessary_await_in_return: - status: needsFix - notes: |- - The fix is to remove the `await`. + status: hasFix LintCode.unnecessary_brace_in_string_interps: status: hasFix LintCode.unnecessary_breaks: diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index ffd0e76e532b..a7c863ebafe7 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -571,6 +571,9 @@ final _builtInLintProducers = >{ AddAwait.unawaited, WrapInUnawaited.new, ], + LintNames.unnecessary_await_in_return: [ + RemoveAwait.new, + ], LintNames.unnecessary_brace_in_string_interps: [ RemoveInterpolationBraces.new, ], diff --git a/pkg/analysis_server/lib/src/services/linter/lint_names.dart b/pkg/analysis_server/lib/src/services/linter/lint_names.dart index b576a42f2c79..5fa3ec8149bc 100644 --- a/pkg/analysis_server/lib/src/services/linter/lint_names.dart +++ b/pkg/analysis_server/lib/src/services/linter/lint_names.dart @@ -157,6 +157,8 @@ class LintNames { static const String type_literal_in_constant_pattern = 'type_literal_in_constant_pattern'; static const String unawaited_futures = 'unawaited_futures'; + static const String unnecessary_await_in_return = + 'unnecessary_await_in_return'; static const String unnecessary_brace_in_string_interps = 'unnecessary_brace_in_string_interps'; static const String unnecessary_breaks = 'unnecessary_breaks'; diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_await_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_await_test.dart index 33e28a94b4ed..071e02c1605f 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/remove_await_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/remove_await_test.dart @@ -13,6 +13,7 @@ void main() { defineReflectiveSuite(() { defineReflectiveTests(RemoveAwaitBulkTest); defineReflectiveTests(RemoveAwaitTest); + defineReflectiveTests(UnnecessaryAwaitInReturnLintTest); }); } @@ -77,3 +78,46 @@ bad() async { '''); } } + +@reflectiveTest +class UnnecessaryAwaitInReturnLintTest extends FixProcessorLintTest { + @override + FixKind get kind => DartFixKind.REMOVE_AWAIT; + + @override + String get lintCode => LintNames.unnecessary_await_in_return; + + Future test_arrow() async { + await resolveTestCode(r''' +class A { + Future f() async => await future; +} +final future = Future.value(1); +'''); + await assertHasFix(r''' +class A { + Future f() async => future; +} +final future = Future.value(1); +'''); + } + + Future test_expressionBody() async { + await resolveTestCode(r''' +class A { + Future f() async { + return await future; + } +} +final future = Future.value(1); +'''); + await assertHasFix(r''' +class A { + Future f() async { + return future; + } +} +final future = Future.value(1); +'''); + } +} From 177ad1a8954936d2e2d8262bac1b0a348414745b Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 21 May 2024 23:45:02 +0000 Subject: [PATCH 2/2] quick fix for `DUPLICATED_MODIFIER` Change-Id: Ibcfbee84b8bcd67cab81741f65e701012f6a4ce9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367362 Commit-Queue: Phil Quitslund Reviewed-by: Brian Wilkerson --- .../services/correction/error_fix_status.yaml | 4 +--- .../src/services/correction/fix_internal.dart | 3 +++ .../fix/remove_extra_modifier_test.dart | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index 29483e544eca..9c5ceec9498b 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -2696,9 +2696,7 @@ ParserErrorCode.DUPLICATE_PREFIX: notes: |- Remove the duplicate. ParserErrorCode.DUPLICATED_MODIFIER: - status: needsFix - notes: |- - Remove the duplicate. + status: hasFix ParserErrorCode.EMPTY_ENUM_BODY: status: noFix notes: |- diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index a7c863ebafe7..9971b7832059 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -1335,6 +1335,9 @@ final _builtInNonLintProducers = >{ ParserErrorCode.DEFAULT_IN_SWITCH_EXPRESSION: [ ReplaceWithWildcard.new, ], + ParserErrorCode.DUPLICATED_MODIFIER: [ + RemoveExtraModifier.new, + ], ParserErrorCode.EXPECTED_TOKEN: [ InsertSemicolon.new, ReplaceWithArrow.new, diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_extra_modifier_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_extra_modifier_test.dart index 5d753dbaff26..fe2f010dcf35 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/remove_extra_modifier_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/remove_extra_modifier_test.dart @@ -51,7 +51,22 @@ class RemoveExtraModifierTest extends FixProcessorTest { @override FixKind get kind => DartFixKind.REMOVE_EXTRA_MODIFIER; - test_invalidAsyncConstructorModifier() async { + Future test_duplicatedModifier() async { + await resolveTestCode(r''' +f() { + const const c = ''; + c; +} +'''); + await assertHasFix(''' +f() { + const c = ''; + c; +} +'''); + } + + Future test_invalidAsyncConstructorModifier() async { await resolveTestCode(r''' class A { A() async {}