From 643733b42eef0b803d404c43a6f3934346889c32 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 22 May 2026 10:30:17 -0700 Subject: [PATCH] [analyzer etc] Add ignores for codegen to prepare for new syntax. (Part of https://github.com/dart-lang/sdk/issues/63288) Updates the `CodeGenerator` mixin so that it outputs `ignore_for_file` comments to ignore the following lints: - unnecessary_type_name_in_constructor - unnecessary_ignore - duplicate_ignore This mixin is used by the code generators that produce the Dart wrappers for the analysis server and analyzer plugin wire protocols. This is a first step towards migrating the packages `analysis_server`, `analysis_server_client`, and `analyzer_plugin` packages to use the new constructor declaration syntax, since it will allow the `unnecessary_type_name_in_constructor` lint to be enabled without breaking generated code. Once all the packages have had their SDK constraints bumped to a language version that supports the new syntax, I'll update the code generator to use the new syntax, and remove the ignores. For more information about the new constructor declaration syntax, see https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations. Change-Id: Ied17e3ea772546675aad48efc324f6f16a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505521 Commit-Queue: Paul Berry Reviewed-by: Samuel Rawlins --- .../support/integration_test_methods.dart | 3 +++ .../support/protocol_matchers.dart | 3 +++ .../lib/protocol/protocol_constants.dart | 3 +++ .../lib/protocol/protocol_generated.dart | 3 +++ .../lib/handler/notification_handler.dart | 3 +++ .../lib/src/protocol/protocol_common.dart | 3 +++ .../lib/src/protocol/protocol_constants.dart | 3 +++ .../lib/src/protocol/protocol_generated.dart | 3 +++ .../lib/protocol/protocol_common.dart | 3 +++ .../lib/protocol/protocol_constants.dart | 3 +++ .../lib/protocol/protocol_generated.dart | 3 +++ .../support/integration_test_methods.dart | 3 +++ .../support/protocol_matchers.dart | 3 +++ pkg/analyzer_utilities/lib/tools.dart | 21 +++++++++++++++++-- 14 files changed, 58 insertions(+), 2 deletions(-) diff --git a/pkg/analysis_server/integration_test/support/integration_test_methods.dart b/pkg/analysis_server/integration_test/support/integration_test_methods.dart index d259ce807c9..8625e6a6ce3 100644 --- a/pkg/analysis_server/integration_test/support/integration_test_methods.dart +++ b/pkg/analysis_server/integration_test/support/integration_test_methods.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + /// Convenience methods for running integration tests. library; diff --git a/pkg/analysis_server/integration_test/support/protocol_matchers.dart b/pkg/analysis_server/integration_test/support/protocol_matchers.dart index dab48f1c57b..cb2ae499550 100644 --- a/pkg/analysis_server/integration_test/support/protocol_matchers.dart +++ b/pkg/analysis_server/integration_test/support/protocol_matchers.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + /// Matchers for data types defined in the analysis server API. library; diff --git a/pkg/analysis_server/lib/protocol/protocol_constants.dart b/pkg/analysis_server/lib/protocol/protocol_constants.dart index 0c0562b01c3..2bcf0efc431 100644 --- a/pkg/analysis_server/lib/protocol/protocol_constants.dart +++ b/pkg/analysis_server/lib/protocol/protocol_constants.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + // ignore: constant_identifier_names const String PROTOCOL_VERSION = '1.40.1'; diff --git a/pkg/analysis_server/lib/protocol/protocol_generated.dart b/pkg/analysis_server/lib/protocol/protocol_generated.dart index a621c6b82df..cba5f314cf2 100644 --- a/pkg/analysis_server/lib/protocol/protocol_generated.dart +++ b/pkg/analysis_server/lib/protocol/protocol_generated.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + import 'dart:convert' hide JsonDecoder; import 'package:analysis_server/protocol/protocol.dart'; diff --git a/pkg/analysis_server_client/lib/handler/notification_handler.dart b/pkg/analysis_server_client/lib/handler/notification_handler.dart index e9e3059fd9d..5b9c58255c1 100644 --- a/pkg/analysis_server_client/lib/handler/notification_handler.dart +++ b/pkg/analysis_server_client/lib/handler/notification_handler.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + import 'package:analysis_server_client/protocol.dart'; /// [NotificationHandler] processes analysis server notifications diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart index 94a35bf8fca..9659fbf15a4 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + import 'dart:convert' hide JsonDecoder; import 'package:collection/collection.dart' show QueueList; diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart index 0c0562b01c3..2bcf0efc431 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + // ignore: constant_identifier_names const String PROTOCOL_VERSION = '1.40.1'; diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart index 278872ba738..b7ff6718dd2 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + import 'dart:convert' hide JsonDecoder; import 'package:analysis_server_client/src/protocol/protocol_base.dart'; diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_common.dart b/pkg/analyzer_plugin/lib/protocol/protocol_common.dart index eb1d342d99d..90abd7eb996 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_common.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_common.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + import 'dart:convert' hide JsonDecoder; import 'package:collection/collection.dart' show QueueList; diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart b/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart index 8103dc3e4d5..765a32eb6f9 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + const String ANALYSIS_NOTIFICATION_ERRORS = 'analysis.errors'; const String ANALYSIS_NOTIFICATION_ERRORS_ERRORS = 'errors'; const String ANALYSIS_NOTIFICATION_ERRORS_FILE = 'file'; diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart b/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart index 624ec4887e2..21234d776ed 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + import 'dart:convert' hide JsonDecoder; import 'package:analyzer_plugin/protocol/protocol.dart'; diff --git a/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart b/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart index f0f9c20c532..853bf6ecd90 100644 --- a/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart +++ b/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + /// Convenience methods for running integration tests. library; diff --git a/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart b/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart index 738a2286254..c093409a52b 100644 --- a/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart +++ b/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart @@ -6,6 +6,9 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor + /// Matchers for data types defined in the analysis server API. library; diff --git a/pkg/analyzer_utilities/lib/tools.dart b/pkg/analyzer_utilities/lib/tools.dart index 81cb13d903c..0391188eb1b 100644 --- a/pkg/analyzer_utilities/lib/tools.dart +++ b/pkg/analyzer_utilities/lib/tools.dart @@ -40,8 +40,9 @@ String capitalize(String string) { /// Type of functions used to compute the contents of a set of generated files. /// [pkgRoot] is the path to the SDK's `pkg` directory. -typedef DirectoryContentsComputer = - Map Function(String pkgRoot); +typedef DirectoryContentsComputer = Map Function( + String pkgRoot, +); /// Type of functions used to compute the contents of a generated file. /// [pkgRoot] is the path to the SDK's `pkg` directory. @@ -191,6 +192,22 @@ mixin CodeGenerator { // This file has been automatically generated. Please do not edit it manually. // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". +'''; + // During the transition period to Dart language version 3.13, some + // generated files will be using language version 3.13, and will have the + // `unnecessary_type_name_in_constructor` lint enabled in order to + // encourage use of the new constructor declaration syntax. Others will be + // using older language versions that don't support this syntax. To ease + // the transition, ignore the `unnecessary_type_name_in_constructor` lint + // in generated code. Also ignore the `unnecessary_ignore` and + // `duplicate_ignore` lints, which would otherwise sometimes be triggered + // by the ignores we're adding. + // TODO(paulberry): clean this up once all generated code is using Dart + // language version 3.13. + header += ''' + +// ignore_for_file: unnecessary_ignore, duplicate_ignore +// ignore_for_file: unnecessary_type_name_in_constructor '''; } writeln(header.trim());