Skip to content

Commit 9e51c2f

Browse files
pqCommit Queue
authored and
Commit Queue
committed
quick fix for EMPTY_RECORD_TYPE_WITH_COMMA
(Also improves fix description for `EMPTY_RECORD_LITERAL_WITH_COMMA`.) See: #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>
1 parent 92b744d commit 9e51c2f

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

pkg/analysis_server/lib/src/services/correction/dart/remove_comma.dart

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar
99
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
1010

1111
class RemoveComma extends ResolvedCorrectionProducer {
12-
RemoveComma({required super.context});
12+
final String targetDescription;
13+
14+
RemoveComma.emptyRecordLiteral({required CorrectionProducerContext context})
15+
: this._(context: context, targetDescription: 'empty record literals');
16+
17+
RemoveComma.emptyRecordType({required CorrectionProducerContext context})
18+
: this._(context: context, targetDescription: 'empty record types');
19+
20+
RemoveComma._({required super.context, required this.targetDescription});
1321

1422
@override
1523
CorrectionApplicability get applicability =>
@@ -18,6 +26,9 @@ class RemoveComma extends ResolvedCorrectionProducer {
1826
@override
1927
FixKind get fixKind => DartFixKind.REMOVE_COMMA;
2028

29+
@override
30+
List<String>? get multiFixArguments => [targetDescription];
31+
2132
@override
2233
FixKind get multiFixKind => DartFixKind.REMOVE_COMMA_MULTI;
2334

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
#
4646
# Stats:
4747
# - 42 "needsEvaluation"
48-
# - 324 "needsFix"
49-
# - 423 "hasFix"
48+
# - 323 "needsFix"
49+
# - 424 "hasFix"
5050
# - 517 "noFix"
5151

5252
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR:
@@ -2646,17 +2646,13 @@ ParserErrorCode.EMPTY_ENUM_BODY:
26462646
added.
26472647
ParserErrorCode.EMPTY_RECORD_LITERAL_WITH_COMMA:
26482648
status: hasFix
2649-
notes: |-
2650-
Remove the comma.
26512649
ParserErrorCode.EMPTY_RECORD_TYPE_NAMED_FIELDS_LIST:
26522650
status: noFix
26532651
notes: |-
26542652
It's likely that the user just hasn't provided a named field yet, and
26552653
offering to remove the braces would be counter-productive.
26562654
ParserErrorCode.EMPTY_RECORD_TYPE_WITH_COMMA:
2657-
status: needsFix
2658-
notes: |-
2659-
Remove the comma.
2655+
status: hasFix
26602656
ParserErrorCode.ENUM_IN_CLASS:
26612657
status: needsFix
26622658
notes: |-

pkg/analysis_server/lib/src/services/correction/fix.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ class DartFixKind {
10261026
static const REMOVE_COMMA_MULTI = FixKind(
10271027
'dart.fix.remove.comma.multi',
10281028
DartFixKindPriority.IN_FILE,
1029-
'Remove commas everywhere in file',
1029+
'Remove commas from {0} everywhere in file',
10301030
);
10311031
static const REMOVE_COMPARISON = FixKind(
10321032
'dart.fix.remove.comparison',

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,10 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
13881388
RemoveLexeme.modifier,
13891389
],
13901390
ParserErrorCode.EMPTY_RECORD_LITERAL_WITH_COMMA: [
1391-
RemoveComma.new,
1391+
RemoveComma.emptyRecordLiteral,
1392+
],
1393+
ParserErrorCode.EMPTY_RECORD_TYPE_WITH_COMMA: [
1394+
RemoveComma.emptyRecordType,
13921395
],
13931396
ParserErrorCode.EXPECTED_TOKEN: [
13941397
InsertSemicolon.new,

pkg/analysis_server/test/src/services/correction/fix/remove_comma_test.dart

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ f() {
4848
f() {
4949
();
5050
}
51+
''');
52+
}
53+
54+
Future<void> test_emptyRecordType() async {
55+
await resolveTestCode('''
56+
(,)? f() => null;
57+
''');
58+
await assertHasFix('''
59+
()? f() => null;
5160
''');
5261
}
5362
}

0 commit comments

Comments
 (0)