quick fix for EMPTY_RECORD_TYPE_WITH_COMMA

(Also improves fix description for `EMPTY_RECORD_LITERAL_WITH_COMMA`.)

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

Change-Id: I742506d8c1a77b10f99861aa84947f8d348916df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371342
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
pq 2024-06-13 17:05:54 +00:00 committed by Commit Queue
parent 92b744d1b2
commit 9e51c2fa74
5 changed files with 29 additions and 10 deletions

View file

@ -9,7 +9,15 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
class RemoveComma extends ResolvedCorrectionProducer {
RemoveComma({required super.context});
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._({required super.context, required this.targetDescription});
@override
CorrectionApplicability get applicability =>
@ -18,6 +26,9 @@ class RemoveComma extends ResolvedCorrectionProducer {
@override
FixKind get fixKind => DartFixKind.REMOVE_COMMA;
@override
List<String>? get multiFixArguments => [targetDescription];
@override
FixKind get multiFixKind => DartFixKind.REMOVE_COMMA_MULTI;

View file

@ -45,8 +45,8 @@
#
# Stats:
# - 42 "needsEvaluation"
# - 324 "needsFix"
# - 423 "hasFix"
# - 323 "needsFix"
# - 424 "hasFix"
# - 517 "noFix"
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR:
@ -2646,17 +2646,13 @@ ParserErrorCode.EMPTY_ENUM_BODY:
added.
ParserErrorCode.EMPTY_RECORD_LITERAL_WITH_COMMA:
status: hasFix
notes: |-
Remove the comma.
ParserErrorCode.EMPTY_RECORD_TYPE_NAMED_FIELDS_LIST:
status: noFix
notes: |-
It's likely that the user just hasn't provided a named field yet, and
offering to remove the braces would be counter-productive.
ParserErrorCode.EMPTY_RECORD_TYPE_WITH_COMMA:
status: needsFix
notes: |-
Remove the comma.
status: hasFix
ParserErrorCode.ENUM_IN_CLASS:
status: needsFix
notes: |-

View file

@ -1026,7 +1026,7 @@ class DartFixKind {
static const REMOVE_COMMA_MULTI = FixKind(
'dart.fix.remove.comma.multi',
DartFixKindPriority.IN_FILE,
'Remove commas everywhere in file',
'Remove commas from {0} everywhere in file',
);
static const REMOVE_COMPARISON = FixKind(
'dart.fix.remove.comparison',

View file

@ -1388,7 +1388,10 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
RemoveLexeme.modifier,
],
ParserErrorCode.EMPTY_RECORD_LITERAL_WITH_COMMA: [
RemoveComma.new,
RemoveComma.emptyRecordLiteral,
],
ParserErrorCode.EMPTY_RECORD_TYPE_WITH_COMMA: [
RemoveComma.emptyRecordType,
],
ParserErrorCode.EXPECTED_TOKEN: [
InsertSemicolon.new,

View file

@ -48,6 +48,15 @@ f() {
f() {
();
}
''');
}
Future<void> test_emptyRecordType() async {
await resolveTestCode('''
(,)? f() => null;
''');
await assertHasFix('''
()? f() => null;
''');
}
}