Skip to content

Added setterAccessControlLevel #11

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

Merged
merged 2 commits into from
May 15, 2025
Merged

Conversation

NSFatalError
Copy link
Owner

@NSFatalError NSFatalError commented May 15, 2025

Summary by CodeRabbit

  • New Features

    • Added support for detecting and accessing setter-specific access control levels on properties.
  • Bug Fixes

    • Improved accuracy in identifying access control levels for property setters.
  • Tests

    • Enhanced test coverage to verify correct parsing of setter access control levels in various property declarations.

@NSFatalError NSFatalError self-assigned this May 15, 2025
Copy link

coderabbitai bot commented May 15, 2025

"""

Walkthrough

The WithModifiersSyntax extension was reorganized and enhanced to support detection of setter-specific access control levels via a new computed property. The logic for determining access control was refactored to use a new private helper method. Corresponding tests were updated and expanded to verify parsing of setter access control levels in various property scenarios.

Changes

File(s) Change Summary
Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift Split extension into multiple extensions for organization; refactored accessControlLevel to use a new helper; added setterAccessControlLevel.
Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift Enhanced tests to verify parsing of setter access control levels; updated expectations and added new assertions for various property scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Property as Property Declaration
    participant WithModifiers as WithModifiersSyntax
    participant Modifiers as Modifiers List

    Property->>WithModifiers: Query accessControlLevel
    WithModifiers->>WithModifiers: accessControlLevel(detail: nil)
    WithModifiers->>Modifiers: Filter modifiers for access control
    Modifiers-->>WithModifiers: Return first matching token
    WithModifiers-->>Property: Return accessControlLevel

    Property->>WithModifiers: Query setterAccessControlLevel
    WithModifiers->>WithModifiers: accessControlLevel(detail: "set")
    WithModifiers->>Modifiers: Filter modifiers for 'set' access control
    Modifiers-->>WithModifiers: Return first matching token or nil
    WithModifiers-->>Property: Return setterAccessControlLevel or fallback to accessControlLevel
Loading

Poem

In the land of code where modifiers dwell,
A rabbit hopped in, with a tale to tell—
Now setters have secrets, their access made clear,
With helpers and tests, the intent draws near.
Organized, precise, with logic anew,
The syntax is sharper, and parsing shines through!
🐇✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between f398c48 and 8b0a4bf.

📒 Files selected for processing (1)
  • Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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: 1

🧹 Nitpick comments (2)
Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift (2)

42-44: Potential confusion about access control level interpretation

The test correctly verifies that accessControlLevel is nil for private(set), but this behavior might be surprising to users who would expect an implicit "internal" access level. Consider adding a comment to clarify this behavior.

 #expect(property.accessControlLevel == nil)
 #expect(property.setterAccessControlLevel?.trimmedDescription == "private")
+// Note: accessControlLevel is nil because the declaration only specifies 
+// an access level for the setter, not for the property itself

36-110: Suggest adding a test case for combined access control modifiers

The tests cover various scenarios but don't include a case for properties with both general and setter-specific access control modifiers (e.g., public private(set) var). This would provide more comprehensive coverage.

@Test
+func testStoredVarWithCombinedAccessControl() throws {
+    let decl: DeclSyntax = """
+    public private(set) var myVar = "Combined access control"
+    """
+    let property = try #require(PropertiesParser.parse(declaration: decl, in: context).first)
+    #expect(property.kind == .stored)
+    #expect(property.mutability == .mutable)
+    #expect(property.accessControlLevel?.trimmedDescription == "public")
+    #expect(property.setterAccessControlLevel?.trimmedDescription == "private")
+    #expect(property.typeScopeSpecifier == nil)
+    #expect(property.trimmedName.description == "myVar")
+    #expect(property.inferredType.description == "String")
+    #expect(property.accessors == nil)
+    #expect(property.observers == nil)
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 22edb9c and f398c48.

📒 Files selected for processing (2)
  • Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (macos)
  • GitHub Check: build-and-test (visionos)
  • GitHub Check: build-and-test (watchos)
  • GitHub Check: build-and-test (ios)
  • GitHub Check: build-and-test (maccatalyst)
🔇 Additional comments (9)
Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (4)

24-25: Well-structured refactoring of extension blocks

Splitting the extensions by related functionality improves code organization and readability.


28-30: Access control level implementation nicely refactored

The implementation now delegates to a private helper method, enabling code reuse while maintaining behavior.


32-34: Good implementation of setter access control detection

The new property correctly looks for setter-specific access control with appropriate fallback to the general access control level.


36-41: Well-designed helper method for access control detection

The implementation efficiently filters modifiers by detail and finds the first matching access control level. The lazy evaluation is a nice performance optimization.

Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift (5)

26-26: Proper assertion for setter access level on immutable property

For immutable properties, the setter access level should match the general access level.


37-38: Good test case for setter-specific access control

Changed from simple private variable to testing a setter-specific access control modifier.


63-63: Appropriate assertion for property without explicit setter access control

The test correctly verifies that setterAccessControlLevel is nil when no setter-specific access control is specified.


83-83: Correct assertion for computed property's setter access level

For computed properties without explicit setter access control, the setter access level should match the general access level.


103-103: Correct assertion for property without any access control specified

Test correctly verifies that both the property and setter access levels are nil when no access control is specified.

Comment on lines +42 to +44
}

extension WithModifiersSyntax {
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider adding test for combined access control modifiers

The current implementation handles setter-specific modifiers well, but I don't see any test for combined modifiers like public private(set) var.


🏁 Script executed:

#!/bin/bash
# Check if there are test cases for combined access control modifiers like 'public private(set) var'
grep -r "public\s\+private(set)" --include="*.swift" Tests/

Length of output: 61


To ensure we haven’t missed any existing tests around public private(set), let’s broaden our search:


🏁 Script executed:

#!/bin/bash
# Search for the exact combined modifier and any private(set) usage in Swift tests
grep -R -E "public\s+private\(set\)" --include="*.swift" Tests/ -n
grep -R "private(set)" --include="*.swift" Tests/ -n

Length of output: 238


Add tests for combined access control modifiers

We already have coverage for private(set) in Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift (line 37), but there’s no test exercising a declaration like

public private(set) var myVar = "Hello, world!"

Please add at least one parser test for the combined modifier scenario. For example, in PropertiesParserTests.swift:

func testPublicPrivateSetVar() throws {
    let source = "public private(set) var myVar = 42"
    let syntax = try parseDeclaration(source)
    XCTAssertTrue(syntax.modifiers.contains(.public))
    XCTAssertTrue(syntax.modifiers.contains(.privateSet))
    // …additional asserts…
}
🤖 Prompt for AI Agents
In Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift around
lines 42 to 44, the review suggests adding a test for combined access control
modifiers like 'public private(set) var'. To fix this, add a new parser test in
Tests/PrincipleMacrosTests/Parsers/PropertiesParserTests.swift that parses a
declaration with combined modifiers, such as "public private(set) var myVar =
42", and assert that both .public and .privateSet modifiers are correctly
recognized in the syntax tree.

Copy link

codecov bot commented May 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@NSFatalError NSFatalError merged commit b2671db into main May 15, 2025
9 checks passed
@NSFatalError NSFatalError deleted the feature/setter-access-control branch May 15, 2025 16:01
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