quick fix for REPRESENTATION_FIELD_TRAILING_COMMA

See: https://github.com/dart-lang/sdk/issues/55917

Change-Id: Ib278e49749618325c8c5fcc7a5627840f87c4553
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371401
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
pq 2024-06-13 18:02:14 +00:00 committed by Commit Queue
parent 1ea71b4b9b
commit dcf72c0882
5 changed files with 27 additions and 9 deletions

View file

@ -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<String>? get multiFixArguments => [targetDescription];
List<String>? get multiFixArguments => [commaKind, targetDescription];
@override
FixKind get multiFixKind => DartFixKind.REMOVE_COMMA_MULTI;

View file

@ -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:

View file

@ -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',

View file

@ -1487,6 +1487,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
ParserErrorCode.RECORD_TYPE_ONE_POSITIONAL_NO_TRAILING_COMMA: [
AddTrailingComma.new,
],
ParserErrorCode.REPRESENTATION_FIELD_TRAILING_COMMA: [
RemoveComma.representationField,
],
ParserErrorCode.SEALED_MIXIN: [
RemoveLexeme.modifier,
],

View file

@ -57,6 +57,15 @@ f() {
''');
await assertHasFix('''
()? f() => null;
''');
}
Future<void> test_representationFieldTrailingComma() async {
await resolveTestCode('''
extension type A(int i,) {}
''');
await assertHasFix('''
extension type A(int i) {}
''');
}
}