Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades analyzer, source_gen, dart_style #1140

Conversation

Rexios80
Copy link

@Rexios80 Rexios80 commented Dec 20, 2024

Cannot upgrade freezed_lint until custom_lint is upgraded which requires these changes. Sort of a chicken/egg problem.

Summary by CodeRabbit

  • New Features
    • Updated dependencies for improved functionality and compatibility.
      • analyzer now supports a broader range of versions.
      • source_gen upgraded to a major new version.
      • dart_style updated to a major new version.
  • Improvements
    • Enhanced readability and structure in the freezed function.
    • Improved logic for retrieving enclosing class elements in the ConstructorX extension.
    • Enhanced method for gathering top-level elements from multiple library units.
    • Expanded search for library import prefixes for more accurate type resolution.

Copy link

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request includes updates to the pubspec.yaml file for the freezed package, where the versions of three dependencies—analyzer, source_gen, and dart_style—have been upgraded to newer ranges. Additionally, changes were made to various files in the codebase, improving the readability and logic of functions related to builders, type resolution, and library element retrieval without altering their public interfaces.

Changes

File Change Summary
packages/freezed/pubspec.yaml - Updated analyzer from >=6.5.0 <7.0.0 to >=6.5.0 <8.0.0
- Updated source_gen from ^1.4.0 to ^2.0.0
- Updated dart_style from ^2.3.6 to ^3.0.0
packages/freezed/lib/builder.dart - Modified freezed function for improved readability and added conditional logic for formatOutput.
packages/freezed/lib/src/ast.dart - Updated fullName and escapedName properties to use declaredElement!.enclosingElement3.
packages/freezed/lib/src/tools/recursive_import_locator.dart - Changed logic in findAllAvailableTopLevelElements to aggregate exports and imports from all units.
packages/freezed/lib/src/tools/type.dart - Updated resolveFullTypeStringFrom to expand search for library import prefixes across all units.

Poem

🐰 Hop, hop, dependencies dance!
Versions leap with each new chance
Analyzer, source_gen, dart_style too
Updating libraries, fresh and new
A rabbit's code grows ever bright 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/freezed/lib/builder.dart (1)

17-30: Consider documenting the format configuration option.

The new format configuration option provides useful flexibility, but its purpose and usage should be documented.

Add a documentation comment above the freezed function:

/// Builds generators for `build_runner` to run
+ ///
+ /// Configuration options:
+ /// - `format`: When set to `false`, disables output formatting. Default: `true`
Builder freezed(BuilderOptions options) {
packages/freezed/lib/src/ast.dart (1)

Line range hint 73-85: Consider extracting common code into a helper method.

The logic for handling generics is duplicated between fullName and escapedName. Consider extracting it into a helper method.

+ String _buildGenericsString(Element classElement) {
+   var generics = classElement.typeParameters
+       .map((e) => '\$${e.name}')
+       .join(', ');
+   return generics.isEmpty ? '' : '<$generics>';
+ }

  String get fullName {
    final classElement = declaredElement!.enclosingElement3;
-   var generics = classElement.typeParameters
-       .map((e) => '\$${e.name}')
-       .join(', ');
-   if (generics.isNotEmpty) {
-     generics = '<$generics>';
-   }
+   final generics = _buildGenericsString(classElement);
    // ... rest of the method
  }

  String get escapedName {
    final classElement = declaredElement!.enclosingElement3;
-   var generics = classElement.typeParameters
-       .map((e) => '\$${e.name}')
-       .join(', ');
-   if (generics.isNotEmpty) {
-     generics = '<$generics>';
-   }
+   final generics = _buildGenericsString(classElement);
    // ... rest of the method
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4b24b and a568fae.

📒 Files selected for processing (4)
  • packages/freezed/lib/builder.dart (1 hunks)
  • packages/freezed/lib/src/ast.dart (1 hunks)
  • packages/freezed/lib/src/tools/recursive_import_locator.dart (1 hunks)
  • packages/freezed/lib/src/tools/type.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: freezed (packages/freezed, stable, downgrade)
  • GitHub Check: freezed (packages/freezed, stable, get)
🔇 Additional comments (4)
packages/freezed/lib/builder.dart (1)

9-16: LGTM! Good refactoring to improve readability.

The extraction of variables makes the code more maintainable and easier to understand.

packages/freezed/lib/src/ast.dart (1)

59-59: Verify analyzer API compatibility.

The change from enclosingElement to enclosingElement3 suggests adaptation to a newer analyzer API. Let's verify the API compatibility across versions.

Also applies to: 67-67

✅ Verification successful

API change is valid and consistent.

The change from enclosingElement to enclosingElement3 is part of the analyzer package API updates. The codebase consistently uses enclosingElement3 and the package dependencies are properly configured to work with the latest analyzer versions (>=6.5.0).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check analyzer API documentation for enclosingElement3
# Look for any deprecation notices or API changes

# Search for enclosingElement3 usage and documentation
rg -A 5 "enclosingElement3" 

# Search for any TODO or DEPRECATED comments related to element APIs
rg -i "TODO|DEPRECATED.*element" 

Length of output: 2610


Script:

#!/bin/bash
# Search for old API usage
rg "enclosingElement[^3]" 

# Search for migration related files
fd -g "*CHANGELOG*" -g "*MIGRATION*" -g "*UPGRADING*" -X cat {}

Length of output: 252


Script:

#!/bin/bash
# Search for old API usage with simpler pattern
rg "enclosingElement\s*=" 
rg "enclosingElement;" 

# Check analyzer version in pubspec
fd pubspec.yaml --exec cat {}

# Search for changelog with correct syntax
find . -type f -name "CHANGELOG.md" -exec cat {} \;

Length of output: 29958

packages/freezed/lib/src/tools/type.dart (1)

44-46: LGTM! More thorough import prefix resolution.

The change to use units.expand() improves type resolution by considering import prefixes from all compilation units, not just the main one.

packages/freezed/lib/src/tools/recursive_import_locator.dart (1)

34-41: LGTM! Consistent improvement in library element collection.

The change to use units.expand() aligns with the improvements in type.dart, providing more thorough collection of library elements across all compilation units.

This change is part of a broader pattern of improvements in how library elements are collected and processed throughout the codebase.

@rrousselGit
Copy link
Owner

rrousselGit commented Jan 6, 2025

This is challenging because source_gen 2.0.0 isn't supported by Flutter Stable. It requires Dart 3.6.0

But source_gen <2.0.0 doesn't support analyzer 7.0.0

@rrousselGit
Copy link
Owner

mb, fixed

@rrousselGit rrousselGit closed this Jan 6, 2025
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.

2 participants