From 12e648fb92c37282411beb7fba1d1e783033dc1c Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 2 Mar 2026 14:16:59 -0700 Subject: [PATCH 1/5] Support analyzer 6.x in analyzer plugin --- .../lib/src/diagnostic/exhaustive_deps.dart | 21 +++++++++++++++++-- .../non_static_reference_visitor.dart | 2 +- tools/analyzer_plugin/pubspec.yaml | 2 +- .../test/integration/stubs.dart | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart b/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart index 81c75407a..c22d2b437 100644 --- a/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart +++ b/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart @@ -680,7 +680,7 @@ class ExhaustiveDeps extends DiagnosticContributor { // NamedType case. This is for references to generic type parameters // (references to other types will get filtered out by the isDeclaredInPureScope check above). (reference) { - dependency = reference.name.name; + dependency = reference.nameLexeme; // These aren't possible for type annotations. isStable = false; isUsedAsCascadeTarget = false; @@ -1980,7 +1980,7 @@ _Recommendations collectRecommendations({ String? getConstructionExpressionType(Expression node) { if (node is InstanceCreationExpression) { if (node.isConst) return null; - return node.constructorName.type.name.name; + return node.constructorName.type.nameLexeme; } else if (node is ListLiteral) { return _DepType.list; } else if (node is SetOrMapLiteral) { @@ -2365,3 +2365,20 @@ extension> on Iterable { return true; } } + +extension TypeNameHelper on NamedType { + // Backwards compatibility for various analyzer versions that remove name/name2. + // ignore: unnecessary_this + dynamic get name => this.name2; // Use `this.` to point to real impl if it exists, not extension. + // ignore: unnecessary_this + dynamic get name2 => this.name; // Use `this.` to point to real impl if it exists, not extension. + dynamic get _name => name; + + String get nameLexeme { + final name = _name; + if (name is Identifier) return name.name; + if (name is Token) return name.lexeme; + if (name is String) return name; + throw UnimplementedError('Unexpected type for name: ${name.runtimeType}'); + } +} diff --git a/tools/analyzer_plugin/lib/src/diagnostic/visitors/non_static_reference_visitor.dart b/tools/analyzer_plugin/lib/src/diagnostic/visitors/non_static_reference_visitor.dart index 46596437d..083383090 100644 --- a/tools/analyzer_plugin/lib/src/diagnostic/visitors/non_static_reference_visitor.dart +++ b/tools/analyzer_plugin/lib/src/diagnostic/visitors/non_static_reference_visitor.dart @@ -70,7 +70,7 @@ bool referencesImplicitThis(SimpleIdentifier identifier) { } // not a class member final Element? enclosingElement = element.enclosingElement; - if (enclosingElement is! InterfaceOrAugmentationElement) { + if (enclosingElement is! InterfaceElement) { return false; } // comment diff --git a/tools/analyzer_plugin/pubspec.yaml b/tools/analyzer_plugin/pubspec.yaml index 09bf75bbc..2bee645c1 100644 --- a/tools/analyzer_plugin/pubspec.yaml +++ b/tools/analyzer_plugin/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/Workiva/over_react/tree/master/tools/analyzer_plu environment: sdk: '>=2.19.0 <3.0.0' dependencies: - analyzer: ^5.11.0 + analyzer: '>=5.11.0 <7.0.0' analyzer_plugin: ^0.11.0 collection: ^1.15.0-nullsafety.4 meta: ^1.16.0 diff --git a/tools/analyzer_plugin/test/integration/stubs.dart b/tools/analyzer_plugin/test/integration/stubs.dart index 6af6f0050..b66650633 100644 --- a/tools/analyzer_plugin/test/integration/stubs.dart +++ b/tools/analyzer_plugin/test/integration/stubs.dart @@ -101,6 +101,7 @@ class StubServerPlugin implements ServerPlugin { handleEditGetRefactoring(parameters) => throw UnimplementedError(); @override + // ignore: override_on_non_overriding_member handleKytheGetKytheEntries(parameters) => throw UnimplementedError(); @override From 0a03173f8daa9e9b8a67c084e5e37c1488d44b80 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 2 Mar 2026 14:24:31 -0700 Subject: [PATCH 2/5] Fix lint in Dart 2.19.6 --- tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart b/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart index c22d2b437..ed1b10d53 100644 --- a/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart +++ b/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart @@ -2375,7 +2375,7 @@ extension TypeNameHelper on NamedType { dynamic get _name => name; String get nameLexeme { - final name = _name; + final dynamic name = _name; if (name is Identifier) return name.name; if (name is Token) return name.lexeme; if (name is String) return name; From c2c38fa041e2e77089c5bd0551250c393222311e Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 2 Mar 2026 14:26:19 -0700 Subject: [PATCH 3/5] Use nameLexeme from over_react --- .../lib/src/diagnostic/exhaustive_deps.dart | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart b/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart index ed1b10d53..8f8f5efb2 100644 --- a/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart +++ b/tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart @@ -34,6 +34,7 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart' show Location; import 'package:over_react_analyzer_plugin/src/diagnostic/analyzer_debug_helper.dart'; import 'package:over_react_analyzer_plugin/src/diagnostic_contributor.dart'; import 'package:over_react_analyzer_plugin/src/indent_util.dart'; +import 'package:over_react_analyzer_plugin/src/over_react_builder_parsing.dart' show TypeNameHelper; import 'package:over_react_analyzer_plugin/src/util/ast_util.dart'; import 'package:over_react_analyzer_plugin/src/util/function_components.dart'; import 'package:over_react_analyzer_plugin/src/util/pretty_print.dart'; @@ -2365,20 +2366,3 @@ extension> on Iterable { return true; } } - -extension TypeNameHelper on NamedType { - // Backwards compatibility for various analyzer versions that remove name/name2. - // ignore: unnecessary_this - dynamic get name => this.name2; // Use `this.` to point to real impl if it exists, not extension. - // ignore: unnecessary_this - dynamic get name2 => this.name; // Use `this.` to point to real impl if it exists, not extension. - dynamic get _name => name; - - String get nameLexeme { - final dynamic name = _name; - if (name is Identifier) return name.name; - if (name is Token) return name.lexeme; - if (name is String) return name; - throw UnimplementedError('Unexpected type for name: ${name.runtimeType}'); - } -} From 956897f3f7798ec47b9ad831df124f4191a4d2cc Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 2 Mar 2026 14:26:59 -0700 Subject: [PATCH 4/5] Fix deprecated name broken in new analyzer --- tools/analyzer_plugin/lib/src/assist/toggle_stateful.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/analyzer_plugin/lib/src/assist/toggle_stateful.dart b/tools/analyzer_plugin/lib/src/assist/toggle_stateful.dart index 4adf0fbff..ab9cd952e 100644 --- a/tools/analyzer_plugin/lib/src/assist/toggle_stateful.dart +++ b/tools/analyzer_plugin/lib/src/assist/toggle_stateful.dart @@ -47,7 +47,7 @@ class ToggleComponentStatefulness extends AssistContributorBase with ComponentDe await super.computeAssists(request, collector); if (!setupCompute() || !initializeAssistApi(request.result.content)) return; - newComponentBaseClass = _getNewBase(componentSupertypeNode.name.name); + newComponentBaseClass = _getNewBase(componentSupertypeNode.nameLexeme); // If there is no known corresponding base class, short circuit. if (newComponentBaseClass == null) return; From 09181aa13f48285a3ccaca79e2f95a2dc6db7a45 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 2 Mar 2026 14:37:25 -0700 Subject: [PATCH 5/5] Ignore mustCallSuper errors in generated code in tests --- tools/analyzer_plugin/test/unit/util/prop_declaration/util.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/analyzer_plugin/test/unit/util/prop_declaration/util.dart b/tools/analyzer_plugin/test/unit/util/prop_declaration/util.dart index fd19f2242..e481dd115 100644 --- a/tools/analyzer_plugin/test/unit/util/prop_declaration/util.dart +++ b/tools/analyzer_plugin/test/unit/util/prop_declaration/util.dart @@ -42,6 +42,8 @@ Future resolveFileAndGeneratedPart(SharedAnalysisContext sha .where((e) => e.severity != Severity.info && !e.errorCode.name.toLowerCase().startsWith('unused_')) // FIXME(FED-2015) remove once these are properly ignored in generated code .where((e) => e.errorCode.name.toLowerCase() != 'invalid_use_of_visible_for_overriding_member') + // For some reason this is triggering for '$mustCallSuper'; ignore for now. FIXME look into what's going on here + .where((e) => e.errorCode.name.toLowerCase() != 'invalid_annotation_target') .toList(); final libraryResult = await getResolvedUnit(libraryFullPath);