Skip to content

Remove patterns#1152

Merged
rrousselGit merged 3 commits intomasterfrom
remove-pattern
Feb 12, 2025
Merged

Remove patterns#1152
rrousselGit merged 3 commits intomasterfrom
remove-pattern

Conversation

@rrousselGit
Copy link
Copy Markdown
Owner

@rrousselGit rrousselGit commented Feb 11, 2025

Summary by CodeRabbit

  • New Features

    • Added a new flag to improve external constructor behavior.
  • Refactor

    • Removed legacy mapping and conditional logic, streamlining union type handling and data model structures.
  • Documentation

    • Updated changelogs and README to clarify the revised API and union behavior.
  • Tests

    • Removed tests for deprecated mapping functionality and added tests for optional feature handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2025

Warning

Rate limit exceeded

@rrousselGit has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d942902 and 8e737c0.

📒 Files selected for processing (1)
  • packages/freezed/test/private_constructor_test.dart (1 hunks)

Walkthrough

This pull request introduces structural changes across the Freezed codebase. A required isExternal parameter has been added to the ConstructorDetails class, while the MapConfig and WhenConfig classes along with their related parameters have been removed from the Data class. Similar modifications are reflected in generated model files, generator logic, and templates. Documentation and changelogs have been updated accordingly, and a number of tests for mapping and union functionalities have been removed or revised, marking a breaking change in the API.

Changes

File(s) Change Summary
packages/_internal/.../models.dart
packages/freezed/.../models.dart
Added a required isExternal parameter to ConstructorDetails; removed MapConfig and WhenConfig classes and their related parameters from the Data class.
packages/_internal/.../models.freezed.dart
packages/freezed/.../models.freezed.dart
Integrated the isExternal property into mixins and implementations; updated copyWith, toString, equality, and hashCode methods while removing mapping-related properties.
packages/freezed/.../freezed_generator.dart Removed union-generation and validation logic related to map/when configurations; introduced a default isExternal property in constructor details.
packages/freezed/.../templates/abstract_template.dart
packages/freezed/.../concrete_template.dart
packages/freezed/.../prototypes.dart
Eliminated getters and functions for union prototype generation (e.g., _map, _when, and related methods).
packages/freezed/.../test/*
(e.g., generic_test.dart, map_test.dart, multiple_constructors_test.dart, when_test.dart, etc.)
Removed multiple tests for union mapping functionalities; updated test suites and added new tests (e.g., options_test.dart) to reflect the API changes.
packages/freezed_annotation/*
(CHANGELOG.md, freezed_annotation.dart, freezed_annotation.g.dart, test/freezed_test.dart)
Updated changelog and documentation to note breaking changes; removed FreezedMapOptions and FreezedWhenOptions classes, their converters, and associated JSON deserialization functions and tests.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant FreezedGenerator
    participant DataModel
    Developer->>FreezedGenerator: Trigger code generation (@freezed)
    FreezedGenerator->>DataModel: Create model with ConstructorDetails (isExternal flag)
    DataModel-->>FreezedGenerator: Return model with updated structure
    FreezedGenerator-->>Developer: Emit generated code
Loading

Poem

I’m a bunny with a joyful leap,
In code fields where changes softly creep.
isExternal hops into view,
While old maps vanish like morning dew.
With paws so quick and heart so free,
I celebrate clean code with glee! 🐰


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
Copy Markdown

@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/src/freezed_generator.dart (1)

134-142: Remove unused commented-out code.
These lines are fully commented out and no longer enforced, which may cause confusion for future maintainers. If the restriction they enforce is no longer desired, consider fully removing this code to keep the codebase clean.

-    // if (constructor.factoryKeyword == null &&
-    //     (constructor.name?.lexeme != '_' ||
-    //         constructor.parameters.parameters.isNotEmpty)) {
-    //   throw InvalidGenerationSourceError(
-    //     'Classes decorated with @freezed can only have a single non-factory'
-    //     ', without parameters, and named MyClass._()',
-    //     element: constructor.declaredElement,
-    //   );
-    // }
packages/freezed/test/private_constructor_test.dart (1)

9-10: Use direct property access instead of cascade for clarity.
Although c..name triggers property access, using the cascade here could be less intuitive. For clarity, consider c.name.

-    expect(() => c..name, throwsUnsupportedError);
+    expect(() => c.name, throwsUnsupportedError);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c3a14f and 258edac.

⛔ Files ignored due to path filters (1)
  • packages/_internal/pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • packages/_internal/lib/models.dart (1 hunks)
  • packages/_internal/lib/models.freezed.dart (15 hunks)
  • packages/freezed/CHANGELOG.md (1 hunks)
  • packages/freezed/README.md (2 hunks)
  • packages/freezed/lib/src/freezed_generator.dart (3 hunks)
  • packages/freezed/lib/src/models.dart (1 hunks)
  • packages/freezed/lib/src/models.freezed.dart (33 hunks)
  • packages/freezed/lib/src/templates/abstract_template.dart (0 hunks)
  • packages/freezed/lib/src/templates/concrete_template.dart (0 hunks)
  • packages/freezed/lib/src/templates/prototypes.dart (0 hunks)
  • packages/freezed/test/generic_test.dart (0 hunks)
  • packages/freezed/test/integration/multiple_constructors.dart (1 hunks)
  • packages/freezed/test/integration/optional_maybe.dart (0 hunks)
  • packages/freezed/test/map_test.dart (0 hunks)
  • packages/freezed/test/multiple_constructors_test.dart (1 hunks)
  • packages/freezed/test/optional_maybe_test.dart (0 hunks)
  • packages/freezed/test/options_test.dart (1 hunks)
  • packages/freezed/test/private_constructor_test.dart (1 hunks)
  • packages/freezed/test/single_class_constructor_test.dart (0 hunks)
  • packages/freezed/test/when_test.dart (0 hunks)
  • packages/freezed_annotation/CHANGELOG.md (1 hunks)
  • packages/freezed_annotation/lib/freezed_annotation.dart (0 hunks)
  • packages/freezed_annotation/lib/freezed_annotation.g.dart (0 hunks)
  • packages/freezed_annotation/test/freezed_test.dart (0 hunks)
💤 Files with no reviewable changes (12)
  • packages/freezed/test/generic_test.dart
  • packages/freezed/test/map_test.dart
  • packages/freezed_annotation/lib/freezed_annotation.g.dart
  • packages/freezed_annotation/test/freezed_test.dart
  • packages/freezed/test/integration/optional_maybe.dart
  • packages/freezed/lib/src/templates/concrete_template.dart
  • packages/freezed/test/when_test.dart
  • packages/freezed/test/single_class_constructor_test.dart
  • packages/freezed/lib/src/templates/abstract_template.dart
  • packages/freezed_annotation/lib/freezed_annotation.dart
  • packages/freezed/test/optional_maybe_test.dart
  • packages/freezed/lib/src/templates/prototypes.dart
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: freezed (packages/freezed_lint, master, get)
  • GitHub Check: freezed (packages/freezed_annotation, master, get)
  • GitHub Check: freezed (packages/freezed, master, get)
🔇 Additional comments (20)
packages/freezed/lib/src/freezed_generator.dart (2)

17-17: Re-export looks good.
The additional exported symbols FreezedUnionCase and FreezedUnionValue appear consistent with usage in this file and elsewhere.


380-380: Consider scenarios for isExternal usage.
The new isExternal property is always set to false. Verify if you plan to handle external constructors or update the property based on user inputs.

packages/freezed/test/options_test.dart (6)

1-7: Imports appear valid.
No issues found regarding these imports. They align with the testing requirements.


9-23: Verify the no-issue test logic.
This test confirms that optional_maybe.dart compiles without errors. It looks good for ensuring stable integration.


25-33: Confirm compile error check.
The approach to expect a compile error on copyWith usage is effective for verifying that the feature is disabled.


35-50: Valid coverage for disabling toString and ==/hash.
These tests confirm that the features are indeed disabled and behave as expected. Nicely done.


53-65: Thorough testing of toJson disabled behavior.
This ensures that trying to call a disabled toJson triggers a compile error. No issues found.


66-69: Verify forced toJson result.
The test effectively checks that a forced toJson implementation is generated correctly.

packages/_internal/lib/models.dart (1)

45-45: LGTM! Added support for external constructors.

The new isExternal parameter in ConstructorDetails enables proper handling of external constructors.

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

35-35: LGTM! Consistent with internal models.

The changes maintain consistency with the internal models by adding the isExternal parameter.

packages/freezed/test/integration/multiple_constructors.dart (1)

107-107: LGTM! Enhanced type safety with sealed class.

Making NameConflict sealed ensures exhaustive pattern matching and better type safety by requiring all subclasses to be defined in the same file.

packages/freezed/test/multiple_constructors_test.dart (1)

353-353: LGTM! Updated to use Dart's native pattern matching.

The test now uses Dart's native pattern matching syntax with switch expressions, aligning with modern Dart practices.

packages/_internal/lib/models.freezed.dart (3)

1-4: LGTM: Generated code header is properly maintained.

The file correctly maintains the "GENERATED CODE" header with appropriate linter ignores.


241-242: LGTM: New isExternal property added to ConstructorDetails.

The isExternal property is properly added to the mixin with appropriate error handling.


772-790: LGTM: Data class properly updated to remove map/when functionality.

The class structure has been simplified by removing map/when related properties while maintaining essential functionality.

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

26-28: LGTM: Improved documentation for copyWith methods.

Clear and consistent documentation added for copyWith functionality.

packages/freezed_annotation/CHANGELOG.md (1)

1-4: LGTM: Clear documentation of breaking changes.

The changelog properly documents the removal of when/map related options as a breaking change in version 3.0.0.

packages/freezed/CHANGELOG.md (1)

1-4: LGTM: Well-documented breaking change with rationale.

The changelog clearly explains the removal of map/when and variants, providing the rationale that these features have been discouraged since Dart got pattern matching.

packages/freezed/README.md (2)

9-9: LGTM! Enhanced package description.

The updated description better reflects Freezed's capabilities by explicitly mentioning "tagged unions" and "nested classes".


419-419: LGTM! Improved technical accuracy.

The clarification that the generated code will "extend/subclass" rather than "implement" the class is more precise and helps users better understand the inheritance mechanism.

@rrousselGit rrousselGit merged commit 46b2c68 into master Feb 12, 2025
3 checks passed
@rrousselGit rrousselGit deleted the remove-pattern branch February 12, 2025 00:09
Copy link
Copy Markdown

@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

🔭 Outside diff range comments (1)
packages/freezed/lib/src/freezed_generator.dart (1)

12-24: 🛠️ Refactor suggestion

Adjust the fee structure to align with customer incentives.

The implementation of a flat $20 fee on discounted bills could negate the benefit of the discount, especially for smaller purchases or marginal loyalty tiers. This might lead to customer dissatisfaction, as the intent to reward loyalty paradoxically increases the bill.

Revise either the discount percentages or the flat fee application to better align with customer incentives.

Do you want me to generate a revised implementation that aligns better with customer expectations and loyalty rewards?

🧹 Nitpick comments (1)
packages/freezed/lib/src/freezed_generator.dart (1)

4-4: Reminder: Address the TODO comment.

The TODO comment indicates that tests are missing for this function. Please ensure that the additional parameter change is thoroughly tested to confirm that it behaves as expected.

Do you want me to generate the unit testing code or open a new issue to track this task?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 258edac and d942902.

📒 Files selected for processing (5)
  • packages/_internal/lib/models.dart (0 hunks)
  • packages/_internal/lib/models.freezed.dart (1 hunks)
  • packages/freezed/lib/src/freezed_generator.dart (1 hunks)
  • packages/freezed/lib/src/models.dart (0 hunks)
  • packages/freezed/lib/src/models.freezed.dart (21 hunks)
💤 Files with no reviewable changes (2)
  • packages/freezed/lib/src/models.dart
  • packages/_internal/lib/models.dart
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: freezed (packages/freezed_lint, master, get)
  • GitHub Check: freezed (packages/freezed_annotation, master, get)
  • GitHub Check: freezed (packages/freezed, master, get)
🔇 Additional comments (2)
packages/_internal/lib/models.freezed.dart (1)

1-1335: Generated file - no direct modifications needed.

This is an auto-generated file by the Freezed package. Any changes should be made to the source files rather than modifying this file directly.

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

1-1335: Generated file - no direct modifications needed.

This is an auto-generated file by the Freezed package. Any changes should be made to the source files rather than modifying this file directly.

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.

1 participant