Skip to content

Conversation

@xJac0b
Copy link
Contributor

@xJac0b xJac0b commented Jun 4, 2025

  • This PR replaces deprecated members from the analyzer package (e.g. declaredElement and staticElement) with their current equivalents.
  • Changes are based on the official migration guide
  • No functional changes were introduced

@xJac0b xJac0b requested a review from solid-vovabeloded June 4, 2025 16:46
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @xJac0b, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request. This PR focuses on updating the codebase to use the latest APIs from the Dart analyzer package. Specifically, it replaces deprecated members like declaredElement and staticElement with their modern equivalents, such as declaredFragment, element, element2, element3, declaredElement2, library2, name2, name3, variable3, enclosingElement2, and baseElement.nonSynthetic2. The changes are based on the official analyzer element model migration guide. The author states that no functional changes were introduced, meaning this is primarily a refactoring effort to maintain compatibility with newer versions of the analyzer.

Highlights

  • Analyzer API Migration: The core of this PR is migrating away from deprecated members in the analyzer package, adhering to the recommended migration path.
  • Replacement of Element Accessors: Deprecated accessors like declaredElement and staticElement are replaced with newer alternatives such as declaredFragment, element, element2, and element3 depending on the context and type.
  • Updated Element Properties: Properties accessed on elements, such as librarySource, name, variable2, and enclosingElement3, are updated to their new names like library2, name2, name3, variable3, and enclosingElement2.
  • Refactored Override Check: The logic for checking the @override annotation has been refactored to directly inspect metadata rather than relying on a deprecated element property.
  • No Functional Changes: According to the author, these changes are purely for API compatibility and do not alter the behavior or logic of the existing lint rules.

Changelog

Click here to see the changelog
  • lib/src/common/parameters/excluded_identifiers_list_parameter.dart
    • Replaced declaredElement?.name with declaredFragment?.name2.
  • lib/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart
    • Replaced staticElement?.librarySource?.uri.toString() with element?.library2?.uri.toString() for PrefixedIdentifier and SimpleIdentifier.
  • lib/src/lints/avoid_final_with_getter/visitors/avoid_final_with_getter_visitor.dart
    • Updated import from element.dart to element2.dart.
    • Replaced declaredElement: ExecutableElement(...) pattern with declaredFragment: ExecutableFragment(element: ExecutableElement2(...)).
  • lib/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart
    • Updated import from element.dart to element2.dart.
    • Replaced VariableDeclaration case pattern using declaredElement with an explicit check on node.declaredFragment?.element.
    • Refactored getterReferenceId extension getter to use element and variable3 instead of staticElement and variable2.
  • lib/src/lints/avoid_global_state/avoid_global_state_rule.dart
    • Replaced declaredElement?.isPrivate with declaredElement2?.isPrivate.
  • lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart
    • Replaced declaredElement?.isLate with node.isLate.
    • Replaced declaredElement?.type with declaredFragment?.element.type.
  • lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart
    • Added _override constant.
    • Replaced declaredElement?.hasOverride check with a switch statement inspecting metadata for @override.
  • lib/src/lints/avoid_unrelated_type_assertions/visitors/avoid_unrelated_type_assertions_visitor.dart
    • Replaced element with element3 when comparing elements of DartType.
    • Replaced castedType.element?.kind with castedType.element3?.kind.
  • lib/src/lints/avoid_unused_parameters/visitors/avoid_unused_parameters_visitor.dart
    • Updated import from element.dart to element2.dart.
    • Replaced parameter.declaredElement with parameter.declaredFragment?.element.baseElement.nonSynthetic2.
    • Updated the type of the elements set in _IdentifiersVisitor from Element to Element2.
    • Replaced node.staticElement with node.element in _IdentifiersVisitor.
    • Replaced node.staticElement is MethodElement with node.element is MethodElement2 in _InvocationsVisitor.
  • lib/src/lints/avoid_using_api/avoid_using_api_linter.dart
    • Updated import from element.dart to element2.dart.
    • Replaced node.staticElement switch cases with node.element and updated element types (FunctionElement -> LocalFunctionElement || TopLevelFunctionElement, PropertyAccessorElement -> PropertyAccessorElement2).
    • Replaced declaredElement?.type.element?.name with declaredElement2?.type.element3?.name3.
    • Replaced declaredElement?.type.element?.librarySource?.uri.toString() with declaredElement2?.type.element3?.library2?.uri.toString().
    • Replaced staticType.element?.librarySource?.uri.toString() with staticType.element3?.library2?.uri.toString().
    • Replaced staticType.element?.name with staticType.element3?.name3.
    • Replaced staticElement.librarySource?.uri.toString() with element.library2?.uri.toString().
    • Replaced staticElement.name with element.name3.
    • Replaced staticType.element?.name with staticType.element3?.name3.
    • Replaced staticElement.name with element.name3.
    • Replaced element?.name with element2?.name3.
    • Replaced staticElement?.enclosingElement3 with element?.enclosingElement2.
    • Updated type check from ExtensionElement to ExtensionElement2.
    • Replaced enclosingElement.name with enclosingElement.name3.
    • Replaced enclosingElement.librarySource.uri.toString() with enclosingElement.library2.uri.toString().
  • lib/src/lints/avoid_using_api/avoid_using_api_utils.dart
    • Replaced staticElement?.librarySource with element?.library2.
    • Replaced element?.librarySource with element2?.library2.
  • lib/src/utils/typecast_utils.dart
    • Replaced source.element == target.element with source.element3 == target.element3.
    • Replaced e.element == target.element with e.element3 == target.element3.
  • lib/src/utils/types_utils.dart
    • Updated import from element.dart to element2.dart.
    • Replaced this.element with element3.
    • Updated type check from InterfaceElement to InterfaceElement2.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Old elements fade,
New fragments take their place,
Code evolves onward.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the deprecation of analyzer package members by migrating to their new equivalents. The changes are consistent with the official migration guide and have been applied thoroughly across multiple files. The code remains clear, and the PR successfully achieves its goal of updating dependencies without introducing functional changes. Great job on this meticulous update!

Summary of Findings

  • API Migration: The deprecated members from the analyzer package (e.g., declaredElement, staticElement, element, librarySource, name) have been correctly replaced with their modern equivalents (e.g., declaredFragment, element (on SimpleIdentifier), element2/element3 (on types/nodes), library2, name2/name3). This was done consistently across all affected files.
  • Override Check: The logic for checking if a method is an override (e.g., in avoid_returning_widgets_rule.dart) has been updated from Element.hasOverride to inspecting AST node metadata, which aligns with the migration guide's recommendations.
  • Code Clarity: Despite the mechanical nature of many changes, the resulting code remains readable and maintains the original logic. In some cases, such as the direct use of VariableDeclaration.isLate, the new API allows for even clearer code.

Merge Readiness

The changes in this pull request are well-executed and align with the stated objective of migrating deprecated analyzer API members. I found no issues of medium severity or higher. The code appears to be in good shape and, from my perspective, is ready for merging after any standard final checks by the team. As an AI, I am not authorized to approve pull requests.

@solid-vovabeloded
Copy link
Collaborator

solid-vovabeloded commented Jun 5, 2025

@xJac0b, I'm seeing some of the tests fail locally for me right now. Please, take a look:

  avoid_using_api/identifier_extension_source_ban/lib/identifier_extension_source_ban_test.dart:6:19 • Expected to find the lint avoid_using_api on next line but none found. • unfulfilled_expect_lint • ERROR
  avoid_using_api/identifier_extension_source_ban/lib/identifier_extension_source_ban_test.dart:9:19 • Expected to find the lint avoid_using_api on next line but none found. • unfulfilled_expect_lint • ERROR
  number_of_parameters_copy_with_test/lib/src/number_of_parameters_copy_with_test.dart:28:3 • The maximum allowed number of parameters is 2. Try reducing the number of parameters. • number_of_parameters • WARNING
  number_of_parameters_copy_with_test/lib/src/number_of_parameters_copy_with_test.dart:74:3 • The maximum allowed number of parameters is 2. Try reducing the number of parameters. • number_of_parameters • WARNING

To run tests, you can use the dart run custom_lint lint_test command.

@xJac0b xJac0b merged commit 2b11b2f into master Jun 5, 2025
2 checks passed
@xJac0b xJac0b deleted the fix/remove-deprecated-flutter-members branch June 5, 2025 15:07
xJac0b added a commit that referenced this pull request Jun 5, 2025
* fix: remove deprecated members

* style: remove extra spacing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants