diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_comma.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_comma.dart index f7da8cad50e..1dd3ba0ae19 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_comma.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_comma.dart @@ -9,15 +9,23 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; class RemoveComma extends ResolvedCorrectionProducer { + final String commaKind; final String targetDescription; RemoveComma.emptyRecordLiteral({required CorrectionProducerContext context}) : this._(context: context, targetDescription: 'empty record literals'); - RemoveComma.emptyRecordType({required CorrectionProducerContext context}) : this._(context: context, targetDescription: 'empty record types'); + RemoveComma.representationField({required CorrectionProducerContext context}) + : this._( + context: context, + commaKind: 'trailing ', + targetDescription: 'representation fields'); - RemoveComma._({required super.context, required this.targetDescription}); + RemoveComma._( + {required super.context, + this.commaKind = '', + required this.targetDescription}); @override CorrectionApplicability get applicability => @@ -27,7 +35,7 @@ class RemoveComma extends ResolvedCorrectionProducer { FixKind get fixKind => DartFixKind.REMOVE_COMMA; @override - List? get multiFixArguments => [targetDescription]; + List? get multiFixArguments => [commaKind, targetDescription]; @override FixKind get multiFixKind => DartFixKind.REMOVE_COMMA_MULTI; 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 dc210308a25..0356c884573 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,8 +45,8 @@ # # Stats: # - 42 "needsEvaluation" -# - 323 "needsFix" -# - 424 "hasFix" +# - 322 "needsFix" +# - 425 "hasFix" # - 517 "noFix" AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR: @@ -3186,9 +3186,7 @@ ParserErrorCode.REPRESENTATION_FIELD_MODIFIER: status: needsFix notes: Remove it. ParserErrorCode.REPRESENTATION_FIELD_TRAILING_COMMA: - status: needsFix - notes: |- - Remove the comma. + status: hasFix ParserErrorCode.SEALED_ENUM: status: needsEvaluation ParserErrorCode.SEALED_MIXIN: diff --git a/pkg/analysis_server/lib/src/services/correction/fix.dart b/pkg/analysis_server/lib/src/services/correction/fix.dart index 803970f4f54..e72157fee30 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix.dart @@ -1026,7 +1026,7 @@ class DartFixKind { static const REMOVE_COMMA_MULTI = FixKind( 'dart.fix.remove.comma.multi', DartFixKindPriority.IN_FILE, - 'Remove commas from {0} everywhere in file', + 'Remove {0}commas from {1} everywhere in file', ); static const REMOVE_COMPARISON = FixKind( 'dart.fix.remove.comparison', 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 ce8c8ee248d..b465e419bb3 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -1487,6 +1487,9 @@ final _builtInNonLintProducers = >{ ParserErrorCode.RECORD_TYPE_ONE_POSITIONAL_NO_TRAILING_COMMA: [ AddTrailingComma.new, ], + ParserErrorCode.REPRESENTATION_FIELD_TRAILING_COMMA: [ + RemoveComma.representationField, + ], ParserErrorCode.SEALED_MIXIN: [ RemoveLexeme.modifier, ], diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_comma_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_comma_test.dart index e94a586a8db..a7dc295e90d 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/remove_comma_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/remove_comma_test.dart @@ -57,6 +57,15 @@ f() { '''); await assertHasFix(''' ()? f() => null; +'''); + } + + Future test_representationFieldTrailingComma() async { + await resolveTestCode(''' +extension type A(int i,) {} +'''); + await assertHasFix(''' +extension type A(int i) {} '''); } }