Skip to content

Disable format#1160

Merged
rrousselGit merged 3 commits intomasterfrom
disablef-format
Feb 24, 2025
Merged

Disable format#1160
rrousselGit merged 3 commits intomasterfrom
disablef-format

Conversation

@rrousselGit
Copy link
Copy Markdown
Owner

@rrousselGit rrousselGit commented Feb 24, 2025

Summary by CodeRabbit

  • New Features

    • Enabled private constructors in unions for added design flexibility.
    • Introduced an option to control automatic formatting of generated code.
  • Refactor/Style

    • Reorganized changelog entries to clarify non‐breaking changes.
    • Standardized code and test formatting for improved readability and maintainability.
  • Chores

    • Updated Dart SDK requirements and streamlined package dependencies.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 24, 2025

Walkthrough

The changes update the freezed package to support private constructors for unions and add a new formatting option via the builder. The changelog has been reorganized to reclassify breaking changes. The builder and generator now accept a format option, with FreezedGenerator conditionally emitting formatting control comments. Multiple files—including AST, models, templates, and test suites—underwent cosmetic reformatting to improve readability without affecting functionality. Additionally, the pubspec now requires Dart SDK version 3.7.0 or higher and removes an unused dependency.

Changes

File(s) Change Summary
packages/freezed/CHANGELOG.md Reorganized entries: moving breaking changes to "Other changes" and adding a note about private constructors for unions with an example snippet.
packages/freezed/build.yaml
packages/freezed/lib/builder.dart
packages/freezed/lib/src/freezed_generator.dart
Added a new format: true option; updated FreezedGenerator to accept a format parameter; removed the obsolete formatOutput function; and added logic to emit formatting comments (// dart format off/on).
packages/freezed/lib/src/ast.dart
packages/freezed/lib/src/models.dart
packages/freezed/lib/src/parse_generator.dart
packages/freezed/lib/src/string.dart
packages/freezed/lib/src/templates/*
packages/freezed/lib/src/tools/*
packages/freezed/pubspec.yaml
Cosmetic formatting changes for improved readability; updated pubspec: SDK constraint changed to ">=3.7.0 <4.0.0" and removal of the dart_style dependency.
packages/freezed/test/* Refactored test files by consolidating multi-line expressions and adjusting factory constructor parameters and expect calls to enhance clarity, with no change to underlying logic.

Sequence Diagram(s)

sequenceDiagram
    participant BuildConfig as Build Config (build.yaml)
    participant Builder as Freezed Builder
    participant Generator as FreezedGenerator
    participant Output as Generated Output

    BuildConfig->>Builder: Load options { format: true }
    Builder->>Generator: Instantiate with config & format option
    Generator->>Generator: Check if formatting is enabled
    alt Formatting Enabled
        Generator->>Output: Emit "// dart format off"
        Generator->>Output: Generate code
        Generator->>Output: Emit "// dart format on"
    else
        Generator->>Output: Generate code normally
    end
Loading
sequenceDiagram
    participant Dev as Developer
    participant Freezed as Freezed Processor
    participant CodeGen as Code Generator

    Dev->>Freezed: Declare sealed class with private union constructor
    Freezed->>CodeGen: Process and validate private constructor feature
    CodeGen-->>Freezed: Generate union class code with private constructor support
    Freezed-->>Dev: Return enhanced union type implementation
Loading

Possibly related PRs

  • Private unions #1159: Enhances union types by allowing private constructors in union classes, directly complementing the new private constructor feature in this PR.

Poem

I'm a bunny, hopping through the code so bright,
With private paths in unions making things just right.
Format toggles hop in the mix with a cheerful gleam,
Streamlining our builders like a well-crafted dream.
I nibble on clean code and skip with delight—
Happy changes bloom, and my ears twitch with insight! 🐰


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/build.yaml (1)

13-14: Consider setting format: false by default.

Given that the PR objective is to disable format, setting format: true by default might be counterintuitive. Consider setting it to false by default to align with the PR objective.

-          format: true
+          format: false
packages/freezed/CHANGELOG.md (1)

159-159: Remove trailing punctuation from heading.

The heading has a trailing punctuation mark which should be removed according to markdown guidelines.

-### Other changes:
+### Other changes
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

159-159: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 89e2658 and 58d11d3.

📒 Files selected for processing (52)
  • packages/freezed/CHANGELOG.md (1 hunks)
  • packages/freezed/build.yaml (1 hunks)
  • packages/freezed/lib/builder.dart (1 hunks)
  • packages/freezed/lib/src/ast.dart (5 hunks)
  • packages/freezed/lib/src/freezed_generator.dart (4 hunks)
  • packages/freezed/lib/src/models.dart (25 hunks)
  • packages/freezed/lib/src/parse_generator.dart (1 hunks)
  • packages/freezed/lib/src/string.dart (1 hunks)
  • packages/freezed/lib/src/templates/abstract_template.dart (1 hunks)
  • packages/freezed/lib/src/templates/concrete_template.dart (14 hunks)
  • packages/freezed/lib/src/templates/copy_with.dart (8 hunks)
  • packages/freezed/lib/src/templates/from_json_template.dart (3 hunks)
  • packages/freezed/lib/src/templates/parameter_template.dart (10 hunks)
  • packages/freezed/lib/src/templates/properties.dart (2 hunks)
  • packages/freezed/lib/src/templates/prototypes.dart (1 hunks)
  • packages/freezed/lib/src/tools/imports.dart (1 hunks)
  • packages/freezed/lib/src/tools/recursive_import_locator.dart (5 hunks)
  • packages/freezed/lib/src/tools/type.dart (2 hunks)
  • packages/freezed/pubspec.yaml (1 hunks)
  • packages/freezed/test/bidirectional_test.dart (4 hunks)
  • packages/freezed/test/common.dart (1 hunks)
  • packages/freezed/test/common_types_test.dart (9 hunks)
  • packages/freezed/test/compiles_test.dart (1 hunks)
  • packages/freezed/test/concrete_test.dart (1 hunks)
  • packages/freezed/test/data_test.dart (1 hunks)
  • packages/freezed/test/decorator_test.dart (2 hunks)
  • packages/freezed/test/deep_copy_test.dart (12 hunks)
  • packages/freezed/test/equal_test.dart (1 hunks)
  • packages/freezed/test/generic_test.dart (4 hunks)
  • packages/freezed/test/generics_refs_test.dart (2 hunks)
  • packages/freezed/test/hashcode_test.dart (2 hunks)
  • packages/freezed/test/implements_decorator_test.dart (3 hunks)
  • packages/freezed/test/integration/bidirectional.dart (1 hunks)
  • packages/freezed/test/integration/concrete.dart (1 hunks)
  • packages/freezed/test/integration/custom_equals.dart (1 hunks)
  • packages/freezed/test/integration/decorator.dart (1 hunks)
  • packages/freezed/test/integration/deep_copy2.dart (1 hunks)
  • packages/freezed/test/integration/generic.dart (1 hunks)
  • packages/freezed/test/integration/json.dart (12 hunks)
  • packages/freezed/test/integration/multiple_constructors.dart (2 hunks)
  • packages/freezed/test/integration/single_class_constructor.dart (10 hunks)
  • packages/freezed/test/json_test.dart (24 hunks)
  • packages/freezed/test/manual_test.dart (1 hunks)
  • packages/freezed/test/multiple_constructors_test.dart (7 hunks)
  • packages/freezed/test/nullable_test.dart (2 hunks)
  • packages/freezed/test/options_test.dart (2 hunks)
  • packages/freezed/test/recursive_import_locator_test.dart (1 hunks)
  • packages/freezed/test/single_class_constructor_test.dart (18 hunks)
  • packages/freezed/test/source_gen_src.dart (4 hunks)
  • packages/freezed/test/source_gen_test.dart (1 hunks)
  • packages/freezed/test/special_class_name_test.dart (1 hunks)
  • packages/freezed/test/typedef_parameter_test.dart (1 hunks)
✅ Files skipped from review due to trivial changes (43)
  • packages/freezed/test/recursive_import_locator_test.dart
  • packages/freezed/test/special_class_name_test.dart
  • packages/freezed/lib/src/templates/from_json_template.dart
  • packages/freezed/test/implements_decorator_test.dart
  • packages/freezed/lib/src/tools/type.dart
  • packages/freezed/lib/src/templates/prototypes.dart
  • packages/freezed/test/generics_refs_test.dart
  • packages/freezed/test/manual_test.dart
  • packages/freezed/test/common_types_test.dart
  • packages/freezed/lib/src/string.dart
  • packages/freezed/test/nullable_test.dart
  • packages/freezed/test/integration/custom_equals.dart
  • packages/freezed/test/integration/deep_copy2.dart
  • packages/freezed/test/generic_test.dart
  • packages/freezed/lib/src/templates/properties.dart
  • packages/freezed/test/integration/decorator.dart
  • packages/freezed/lib/src/ast.dart
  • packages/freezed/test/decorator_test.dart
  • packages/freezed/lib/src/templates/abstract_template.dart
  • packages/freezed/test/integration/multiple_constructors.dart
  • packages/freezed/test/typedef_parameter_test.dart
  • packages/freezed/lib/src/tools/imports.dart
  • packages/freezed/test/concrete_test.dart
  • packages/freezed/test/common.dart
  • packages/freezed/test/equal_test.dart
  • packages/freezed/test/compiles_test.dart
  • packages/freezed/test/source_gen_src.dart
  • packages/freezed/test/integration/bidirectional.dart
  • packages/freezed/test/bidirectional_test.dart
  • packages/freezed/test/multiple_constructors_test.dart
  • packages/freezed/lib/src/tools/recursive_import_locator.dart
  • packages/freezed/test/integration/generic.dart
  • packages/freezed/test/single_class_constructor_test.dart
  • packages/freezed/test/hashcode_test.dart
  • packages/freezed/lib/src/templates/concrete_template.dart
  • packages/freezed/test/integration/concrete.dart
  • packages/freezed/lib/src/models.dart
  • packages/freezed/test/json_test.dart
  • packages/freezed/lib/src/templates/copy_with.dart
  • packages/freezed/lib/src/templates/parameter_template.dart
  • packages/freezed/test/integration/single_class_constructor.dart
  • packages/freezed/test/integration/json.dart
  • packages/freezed/test/deep_copy_test.dart
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
packages/freezed/CHANGELOG.md

159-159: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: freezed (packages/freezed, master, get)
🔇 Additional comments (18)
packages/freezed/pubspec.yaml (1)

10-10:

Details

✅ Verification successful

Verify the need for Dart SDK 3.7.0.

The SDK version constraint has been updated to require Dart 3.7.0 or higher. Please verify if this version bump is necessary and document the specific features or requirements that necessitate this change.


🌐 Web query:

What are the new features in Dart 3.7.0 that might be relevant for the freezed package?

💡 Result:

Dart 3.7.0 introduces several changes that could impact usage of the freezed package for code generation:

1. Formatter Style Changes

  • A new formatting style now applies to codebases using language version ≥3.7[1][4]
  • Freezed-generated code (like union types) will adopt:
    • Improved indentation for factory constructors
    • More consistent spacing around type parameters
  • Requires developers to run dart format with updated rules[1]

2. Wildcard Pattern Support

  • New _ wildcard syntax for pattern matching[8]:
switch (myFreezedUnion) {
  case Success(:final data, _) => // Ignore secondary parameter
  // ...
}
  • Works seamlessly with Freezed's sealed classes/union types

3. JS Interop Migration

  • Legacy JS interop libraries (dart:js, package:js) deprecated[1]
  • Freezed models interacting with JS should migrate to:
import 'package:web/web.dart' as web; // New recommended approach

4. Toolchain Updates

  • Removed --fix flag from dart format[1]
  • Freezed users should replace:
dart format --fix

with:

dart fix --apply && dart format

Compatibility Notes

  • Freezed v3.x fully supports Dart 3.x features like native sealed classes[2]
  • Formatting changes are backward-compatible but may require CI/CD updates[4]
  • Wildcard patterns work with existing Freezed models without modifications[8]

Developers should update analysis options to handle new formatting rules and consider migrating JS-dependent models to the new web interop package[1][4].

Citations:


SDK Bump Rationale Verification for packages/freezed/pubspec.yaml

The update to the SDK constraint "sdk: ">=3.7.0 <4.0.0"" appears justified based on Dart 3.7.0’s new features that directly impact the freezed package. In particular:

  • Enhanced Formatting Rules: Updated formatting for factory constructors and union types may require running dart format with new rules.
  • Wildcard Pattern Support: New wildcard syntax improves pattern matching within freezed-generated sealed classes.
  • JS Interop Changes: The deprecation of legacy JS interop libraries mandates migration, impacting models generated by freezed.
  • Toolchain Updates: Adjustments such as replacing the removed --fix flag ensure compatibility with the latest tooling.

Please verify that these changes are in use or will be leveraged in your implementation and update any accompanying documentation to reflect these requirements.

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

22-27: LGTM!

The reformatting improves readability while maintaining the same functionality.

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

19-28: LGTM!

The reformatting improves readability while maintaining the same test logic.

Also applies to: 30-40

packages/freezed/test/source_gen_test.dart (2)

8-11: LGTM!

The reformatting improves readability without affecting functionality.


17-17: LGTM!

The addition of format: false aligns with the new feature to disable formatting in generated files, as documented in the changelog.

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

11-11: LGTM!

The reformatting improves readability without affecting functionality.


17-21: LGTM!

The reformatting of the error result assignment improves readability.


27-36: LGTM!

The reformatting of the expectLater call improves readability.


47-48: LGTM!

The reformatting of test assertions improves readability.


55-64: LGTM!

The reformatting of the expectLater call improves readability.

packages/freezed/lib/builder.dart (1)

10-15: LGTM!

The reformatting and addition of the format parameter improve readability and implement the new formatting control feature.

packages/freezed/CHANGELOG.md (1)

161-173: LGTM!

The changelog entries properly document:

  1. Breaking changes regarding map/when and class requirements
  2. The new formatting control feature
  3. The new private constructor feature for unions
packages/freezed/lib/src/freezed_generator.dart (6)

22-22: LGTM!

The addition of the required format parameter and its corresponding final field follows Dart's best practices.

Also applies to: 25-25


32-34: LGTM!

The reformatting improves readability without affecting functionality.


60-60: LGTM!

The formatting control comments are correctly placed and conditionally added based on the format parameter.

Also applies to: 80-80


83-83: LGTM!

The method signature reformatting improves consistency without affecting functionality.


86-103: LGTM!

The reformatting of the commonCopyWith variable assignment improves readability without affecting functionality.


118-135: LGTM!

The reformatting of the copyWith parameter assignment improves readability without affecting functionality.

@rrousselGit rrousselGit merged commit bdedab5 into master Feb 24, 2025
4 checks passed
@rrousselGit rrousselGit deleted the disablef-format branch February 24, 2025 14:11
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