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

#[builder(on(_, transparent))] attribute #155

Merged
merged 1 commit into from
Oct 25, 2024
Merged

Conversation

Veetaha
Copy link
Contributor

@Veetaha Veetaha commented Oct 25, 2024

Implements the #[builder(on(_, transparent)] that is part of #35.

Unfortunately, this initial implementation is a bit limited (but still useful!). There are two restrictions:

  • It's only possible to specify #[builder(on(_, transparent))] with an _ pattern. No other patterns will be accepted (compile error)
  • It's only possible to specify transparent in the first on. This doesn't compile: #[builder(on(String, into), on(_, transparent))]. Reorder the clauses to this instead: #[builder(on(_, transparent), on(String, into))]

I decided to postpone the extended design #152 for on for later. It's a really complex feature that I'd rather not do as part of the initial 3.0. It's possible to implement that in a minor release (no breaking changes are expected).

This PR doesn't include the documentation for this feature. The docs for all the new behaviors and attributes will be submitted in a separate PR.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages for the #[builder(...)] attribute usage, addressing redundancy, unsupported syntax, and nested attributes.
    • Clarified requirements for on(...) clauses, including order and parameter specifications.
    • Enhanced guidance for using the transparent option within on(...) clauses.

Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request focus on error messages related to the #[builder(...)] attribute in Rust code, specifically within the file tests/integration/ui/compile_fail/attr_on.rs. The modifications clarify various issues such as redundant attributes, unsupported syntax, nested attributes, and errors related to the use of on(...) clauses. Additionally, the changes provide clearer guidance on the correct usage of the transparent option and the order of clauses, enhancing the understanding of the attribute's requirements.

Changes

File Path Change Summary
bon/tests/integration/ui/compile_fail/attr_on.rs - Added error messages for redundant attributes (#[builder(into)], #[builder(overwritable)]).
- Introduced errors for unsupported syntax in #[builder(on(&dyn std::fmt::Debug, into))].
- Highlighted that nested attributes are not allowed in #[builder(on(type_pattern, ...))].
- Addressed issues with empty on attributes (e.g., #[builder(on)], #[builder(on())]).
- Raised errors for missing commas and incorrect usage of on(...) clauses.
- Clarified error messages regarding behavior overrides with #[builder(on(type_pattern, ...))].
- Indicated that certain on(...) clauses are out of order.
- Specified that transparent can only be used in the first on(...) clause with wildcard types.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Compiler
    participant ErrorHandler

    User->>Compiler: Submit Rust code with #[builder(...)]
    Compiler->>ErrorHandler: Check for attribute errors
    ErrorHandler->>Compiler: Return error messages for:
    ErrorHandler-->>User: Display errors (redundant attributes, unsupported syntax, etc.)
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 62e3b9c and f9a3b76.

⛔ Files ignored due to path filters (6)
  • bon-macros/src/builder/builder_gen/input_struct.rs is excluded by !**/*.rs
  • bon-macros/src/builder/builder_gen/member/named.rs is excluded by !**/*.rs
  • bon-macros/src/builder/builder_gen/top_level_config/mod.rs is excluded by !**/*.rs
  • bon-macros/src/builder/builder_gen/top_level_config/on.rs is excluded by !**/*.rs
  • bon/tests/integration/builder/attr_transparent.rs is excluded by !**/*.rs
  • bon/tests/integration/ui/compile_fail/attr_on.rs is excluded by !**/*.rs
📒 Files selected for processing (1)
  • bon/tests/integration/ui/compile_fail/attr_on.stderr (1 hunks)
🔇 Additional comments (4)
bon/tests/integration/ui/compile_fail/attr_on.stderr (4)

45-52: LGTM: Clear and accurate error message

The error message has been updated to include 'transparent' in the list of available options, which aligns well with the new feature implementation.


53-70: LGTM: Clear clause ordering enforcement

The error messages effectively communicate that on(...) clauses must be consecutive, which helps maintain a consistent attribute structure.


71-81: LGTM: Proper enforcement of transparent restrictions

The error messages accurately implement the PR's documented limitations by:

  1. Enforcing that transparent can only be used in the first on(...) clause
  2. Restricting transparent to only work with the wildcard pattern (_)

The messages also helpfully indicate these are temporary restrictions that may be lifted in the future, which aligns with the PR objectives of postponing more complex designs for a future release.


Line range hint 1-81: Verify comprehensive error coverage

Let's ensure all error cases are covered and consistent with the codebase style.

✅ Verification successful

All error cases are properly covered and consistent with codebase style

The verification shows that:

  1. The error messages in attr_on.stderr follow the consistent style pattern of "error: " prefix used throughout the codebase
  2. All error cases for transparent attribute are properly covered, including:
    • Redundant attributes with on(...)
    • Order restrictions
    • Type pattern restrictions
  3. The error messages maintain a clear, descriptive format that explains both the issue and, where applicable, the solution
  4. The error cases align with the documented behavior in the codebase, as evidenced by the implementation comments and tests

The error coverage is comprehensive and the messages follow the established style conventions of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistency in error messages and coverage

# Test 1: Check if there are similar error messages in other test files
echo "Checking for similar error patterns in other test files..."
rg -l "builder.*transparent" tests/

# Test 2: Verify error message style consistency
echo "Checking error message style consistency..."
rg "^error: " tests/ | sort | uniq -c | sort -nr

# Test 3: Look for any TODO/FIXME comments related to error messages
echo "Checking for TODO/FIXME comments in error handling..."
rg -i "todo|fixme|xxx|hack" tests/ -g "*.rs" -g "*.stderr"

Length of output: 631


Script:

#!/bin/bash
# Let's try with the correct path structure by first finding the test files

# Find all test files
echo "Finding test files..."
fd -t f . -e rs -e stderr

# Once we find the files, let's check error patterns
echo -e "\nChecking error patterns..."
rg "builder.*transparent" .

# Check error message style
echo -e "\nChecking error message style..."
rg "^error: " .

# Look for TODOs
echo -e "\nChecking TODOs..."
rg -i "todo|fixme|xxx|hack" . -g "*.rs" -g "*.stderr"

Length of output: 42040


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 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.

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