From f62d10f40cd53a6184d36bf8cfb3ea4d352b8812 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Fri, 10 Apr 2026 13:04:19 -0700 Subject: [PATCH] Update the removeConstructorName fix to handle primary constructors Closes https://github.com/dart-lang/sdk/issues/63072 Change-Id: I3391484a2693b0ec9f520353ac231ee0d9a60c7c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494623 Reviewed-by: Samuel Rawlins Commit-Queue: Brian Wilkerson --- .../correction/dart/remove_constructor_name.dart | 4 ++++ .../fix/remove_constructor_name_test.dart | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_constructor_name.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_constructor_name.dart index d33bbf3b597..8848956ff79 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_constructor_name.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_constructor_name.dart @@ -35,6 +35,10 @@ class RemoveConstructorName extends ResolvedCorrectionProducer { await builder.addDartFileEdit(file, (builder) { builder.addDeletion(range.startStart(dotToken, node.token.next!)); }); + } else if (node is PrimaryConstructorName) { + await builder.addDartFileEdit(file, (builder) { + builder.addDeletion(range.startStart(node.period, node.name.next!)); + }); } } } diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_constructor_name_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_constructor_name_test.dart index bbd6b3698fd..17dcff94ebe 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/remove_constructor_name_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/remove_constructor_name_test.dart @@ -75,7 +75,16 @@ class RemoveConstructorNameTest extends FixProcessorLintTest { @override String get lintCode => LintNames.unnecessary_constructor_name; - Future test_constructorDeclaration() async { + Future test_declaration_primary() async { + await resolveTestCode(r''' +class C.new(int x); +'''); + await assertHasFix(r''' +class C(int x); +'''); + } + + Future test_declaration_secondary() async { await resolveTestCode(r''' class A { A.new(int x) { @@ -92,7 +101,7 @@ class A { '''); } - Future test_constructorInvocation() async { + Future test_invocation() async { await resolveTestCode(r''' class A { } var a = A.new();