From 7ead4b57860626bc7b08b5e8621fa8365e723481 Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 11 Jun 2024 08:03:15 +0000 Subject: [PATCH] quick fix for `MISSING_TYPEDEF_PARAMETERS` See: https://github.com/dart-lang/sdk/issues/55917 Change-Id: I9b81940c1c515bf923ceecb83d5aaad1d416dab1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370482 Commit-Queue: Phil Quitslund Reviewed-by: Brian Wilkerson --- .../correction/dart/add_empty_argument_list.dart | 11 +++++++++-- .../lib/src/services/correction/error_fix_status.yaml | 6 ++---- .../lib/src/services/correction/fix_internal.dart | 3 +++ .../correction/fix/add_empty_argument_list_test.dart | 9 +++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_empty_argument_list.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_empty_argument_list.dart index dbbf87c3150..b4689f9a5b6 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_empty_argument_list.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_empty_argument_list.dart @@ -24,10 +24,17 @@ class AddEmptyArgumentList extends ResolvedCorrectionProducer { @override Future compute(ChangeBuilder builder) async { var node = this.node; - if (node is! AnnotationImpl) return; + int? offset; + if (node is AnnotationImpl) { + offset = node.end; + } else if (node is FunctionTypeAlias) { + // endToken is the trailing `;`. + offset = node.endToken.previous?.end; + } + if (offset == null) return; await builder.addDartFileEdit(file, (builder) { - builder.addSimpleInsertion(node.end, '()'); + builder.addSimpleInsertion(offset!, '()'); }); } } 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 7af45714723..d41422dda4c 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 @@ -45,7 +45,7 @@ # # Stats: # - 42 "needsEvaluation" -# - 334 "needsFix" +# - 331 "needsFix" # - 417 "hasFix" # - 516 "noFix" @@ -3060,9 +3060,7 @@ ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP: notes: |- Add the missing terminator. ParserErrorCode.MISSING_TYPEDEF_PARAMETERS: - status: needsFix - notes: |- - Add an empty parameter list. + status: hasFix ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH: status: noFix ParserErrorCode.MIXED_PARAMETER_GROUPS: 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 6abc959ec27..c5613a32a9d 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -1452,6 +1452,9 @@ final _builtInNonLintProducers = >{ ParserErrorCode.MISSING_FUNCTION_BODY: [ ConvertIntoBlockBody.missingBody, ], + ParserErrorCode.MISSING_TYPEDEF_PARAMETERS: [ + AddEmptyArgumentList.new, + ], ParserErrorCode.MIXIN_DECLARES_CONSTRUCTOR: [ RemoveConstructor.new, ], diff --git a/pkg/analysis_server/test/src/services/correction/fix/add_empty_argument_list_test.dart b/pkg/analysis_server/test/src/services/correction/fix/add_empty_argument_list_test.dart index a065666e291..fe787c2d335 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/add_empty_argument_list_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/add_empty_argument_list_test.dart @@ -61,6 +61,15 @@ class A { } @A() main() {} +'''); + } + + Future test_missingTypedefParameters() async { + await resolveTestCode(''' +typedef F; +'''); + await assertHasFix(''' +typedef F(); '''); } }