Skip to content

Docs #4

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 5 commits into from
Apr 5, 2025
Merged

Docs #4

merged 5 commits into from
Apr 5, 2025

Conversation

NSFatalError
Copy link
Owner

@NSFatalError NSFatalError commented Apr 5, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced CI workflows now streamline the build and test process across multiple platforms.
    • Upgraded dependency versions and platform requirements to leverage the latest Swift tools.
    • Added a verification step for API-breaking changes based on versioning during the release process.
  • Chores

    • Refined YAML workflow formatting and configuration.
    • Improved linting rules for better code style validation.
  • Tests

    • Introduced new test suites validating macro behavior, expression generation, and parameter extraction.
    • Added tests for switch expression generation and enum case handling.
  • Documentation

    • Updated guidance with fresh installation instructions and Swift version details, including a warning about the package's status.

@NSFatalError NSFatalError self-assigned this Apr 5, 2025
Copy link

coderabbitai bot commented Apr 5, 2025

Warning

Rate limit exceeded

@NSFatalError has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 36 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 b38a698 and e2615c4.

📒 Files selected for processing (2)
  • .github/workflows/pull-request.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)

Walkthrough

This pull request restructures several workflows and updates configuration, package, and source files. The pull request workflow now renames the initial job to "prepare" and adds a dependent "build-and-test" job with a matrix strategy to run across multiple platforms. Additionally, minor YAML formatting tweaks were made to the release workflow. The lint configuration now ignores comments for line lengths and has an updated regex. Package files were updated to support newer Swift tools and platform versions. Source files received syntax formatting improvements, and new test suites and naming enhancements were introduced throughout the test modules.

Changes

File(s) Change Summary
.github/workflows/pull-request.yml
.github/workflows/release.yml
Refactored pull request workflow: renamed job to prepare, added new build-and-test job (with dependency and matrix strategy), defined environment variable and outputs, and adjusted step configuration. Also, applied minor YAML formatting fixes in the release workflow.
.swiftlint.yml
Package.resolved
Package.swift
README.md
Updated lint configuration to ignore comments and modified a custom rule regex; in package files, increased Swift tools version, updated platform support and dependency versions; enhanced README with a Swift badge, description, warning, and installation instructions.
Sources/PrincipleMacros/Builders/Expressions/SwitchExprBuilder.swift
Sources/PrincipleMacros/Imports.swift
Improved syntax builder for switch expressions by adding structured formatting (including a new parameter for left brace and multi-line switch cases) and updated import statements with a private documentation attribute.
Tests (all files under Tests/PrincipleMacrosTests/…) Added new test suites for EnumCaseCallExprBuilder, SwitchExprBuilder, and ParameterExtractor; renamed test functions in ClosureExprSyntaxTests from testInterpolation to testExpansion; and updated function signatures in ExprSyntaxTests and TypeSyntaxTests for clearer parameter usage.

Sequence Diagram(s)

sequenceDiagram
    participant PR as Pull Request Event
    participant Prepare as Prepare Job
    participant BuildTest as Build & Test Job

    PR->>Prepare: Trigger workflow
    Note over Prepare: Set XCODE_VERSION and extract platforms/scheme
    Prepare-->>BuildTest: Pass outputs (platforms, scheme)
    BuildTest->>BuildTest: Run build and test matrix across platforms
Loading

Poem

I'm hopping through the code with glee,
A bunny in a workflow spree.
Renamed jobs and tests all align,
Matrix builds and lint rules fine.
With carrots of code all fresh and new,
I celebrate these changes — woohoo! 🐰✨


🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between db8a49d and 3b827e2.

📒 Files selected for processing (14)
  • .github/workflows/pull-request.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .swiftlint.yml (2 hunks)
  • Package.resolved (1 hunks)
  • Package.swift (2 hunks)
  • README.md (1 hunks)
  • Sources/PrincipleMacros/Builders/Expressions/SwitchExprBuilder.swift (2 hunks)
  • Sources/PrincipleMacros/Imports.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Builders/EnumCaseCallExprBuilderTests.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Builders/SwitchExprBuilderTests.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Syntax/ClosureExprSyntaxTests.swift (3 hunks)
  • Tests/PrincipleMacrosTests/Syntax/ExprSyntaxTests.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Syntax/TypeSyntaxTests.swift (2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
Tests/PrincipleMacrosTests/Syntax/TypeSyntaxTests.swift (1)
Tests/PrincipleMacrosTests/Syntax/ExprSyntaxTests.swift (2)
  • testArrayLiteral (46-50)
  • testDictionaryLiteral (52-56)
Tests/PrincipleMacrosTests/Builders/SwitchExprBuilderTests.swift (2)
Tests/PrincipleMacrosTests/Builders/EnumCaseCallExprBuilderTests.swift (1)
  • makeEnumCase (14-18)
Sources/PrincipleMacros/Builders/Expressions/SwitchExprBuilder.swift (1)
  • build (27-33)
🪛 SwiftLint (0.57.0)
Package.swift

[Warning] 6-6: Top-level declarations should specify Access Control Level keywords explicitly

(explicit_top_level_acl)


[Warning] 1-1: Header comments should be consistent with project patterns

(file_header)


[Warning] 6-6: Top-level constants should be prefixed by k

(prefixed_toplevel_constant)

🔇 Additional comments (35)
Tests/PrincipleMacrosTests/Syntax/ExprSyntaxTests.swift (1)

109-111: Good improvement to function signature

Changing from a tuple parameter to named parameters makes the test function more readable and self-documenting. This change aligns with Swift's best practices for API design and improves code maintainability.

Tests/PrincipleMacrosTests/Syntax/TypeSyntaxTests.swift (2)

18-19: Improved variable naming for better semantics

Renaming from expr to type is a good change that better represents the variable's purpose as a TypeSyntax instance rather than an expression. This enhances code readability and makes the intention clearer.

Also applies to: 24-25, 30-31, 36-37, 42-43, 48-49, 54-55, 60-61, 66-67


85-87: Good signature improvement, consistent with ExprSyntaxTests

Similar to the change in ExprSyntaxTests, this improves the function signature by using named parameters instead of a tuple. The change maintains consistency between test files and follows Swift best practices.

Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (8)

14-17: Well-structured helper method!

This helper method is nicely designed, efficiently converting an expression into a ParameterExtractor instance. Using the #require macro for unwrapping is a good practice for tests as it clearly indicates the requirement and will fail with a descriptive message if not met.


19-25: Good test for named parameter extraction.

This test properly validates that the ParameterExtractor can correctly extract a named expression from a macro. The test case is clear and the assertion verifies the expected output matches the actual output.


27-33: Good test for unnamed parameter extraction.

The test correctly handles the extraction of an unnamed expression by passing nil to the withLabel parameter. This demonstrates that the ParameterExtractor supports both named and unnamed parameters, which is important for flexibility in macro usage.


35-41: Comprehensive trailing closure extraction test.

This test validates that trailing closures can be extracted correctly, which is a crucial feature for macros that accept closure parameters. The test properly checks that the extracted closure matches the expected syntax.


43-49: Good test for function reference in trailing closure.

This test validates that the ParameterExtractor can extract function references as trailing closures. This is an important case to cover since Swift allows passing function references directly as closures.


51-56: Clear validation of raw string extraction.

The test effectively validates that the ParameterExtractor can extract raw string values from macro parameters, which is a common use case in macros.


58-64: Great error handling test for unexpected syntax type.

This test properly validates that the ParameterExtractor throws the expected error when attempting to extract a raw string from a reference expression. Error handling tests are crucial for robust API design.


66-72: Good test for parameter not found scenario.

This test ensures that the ParameterExtractor throws the appropriate error when attempting to extract a parameter that doesn't exist in the macro expression. Proper error handling for this case will provide clear feedback to users of the API.

Tests/PrincipleMacrosTests/Syntax/ClosureExprSyntaxTests.swift (3)

23-23: Improved test method naming.

Renaming from testInterpolation to testExpansion better reflects what the test is actually doing - testing the expansion of a closure expression rather than string interpolation. This change improves code clarity and makes the test's purpose more obvious.


56-56: Improved test method naming.

Renaming from testInterpolation to testExpansion better reflects what the test is actually doing - testing the expansion of a closure expression rather than string interpolation. This makes the test's purpose clearer, especially when dealing with closures that have signatures.


97-97: Improved test method naming.

Renaming from testInterpolation to testExpansion better reflects what the test is actually doing - testing the expansion of a multi-line closure expression. This consistent naming convention across all test methods improves the overall clarity of the test suite.

Tests/PrincipleMacrosTests/Builders/SwitchExprBuilderTests.swift (2)

20-30: Well-structured test for switch expression.

The test is well-organized, preparing test data by creating enum cases of varying complexity and then validating the output of the SwitchExprBuilder. The approach of providing a closure that returns the count of associated values is a good way to test the builder's capabilities.


32-44: Good validation against expected output.

The test properly validates that the built switch expression matches the expected output, including pattern matching for the cases with associated values. The expected output includes formatting with proper indentation, which is important for readability of the generated code.

Tests/PrincipleMacrosTests/Builders/EnumCaseCallExprBuilderTests.swift (4)

14-18: Clean and reusable helper method.

This helper method effectively creates an EnumCase instance from a declaration syntax. It's designed to be reused across multiple test methods, which is a good practice for test code organization.


20-28: Good test for enum case without associated values.

This test correctly validates that the EnumCaseCallExprBuilder can build a call expression for an enum case without associated values. The test includes an Issue.record() call, which might be recording information for debugging or metrics.


30-37: Good test for enum case with unnamed associated value.

This test properly validates that the EnumCaseCallExprBuilder can build a call expression for an enum case with an unnamed associated value. The builder correctly formats the call with the provided expression.


39-50: Comprehensive test for enum case with multiple associated values.

This test effectively validates that the EnumCaseCallExprBuilder can build a call expression for an enum case with multiple associated values, including both named and unnamed parameters. The conditionally provided expressions based on the parameter name demonstrate how the builder can handle different types of parameters.

Sources/PrincipleMacros/Builders/Expressions/SwitchExprBuilder.swift (3)

28-32: Great improvement to the switch expression formatting!

The changes to the SwitchExprSyntax initialization properly handle spacing around the subject expression and ensure the left brace has a trailing newline. This will produce more readable and consistently formatted code in the generated output.


39-42: Good switch to multi-line string literal format

Converting to triple-quote string literals for the switch case syntax improves code readability and maintenance. The explicit formatting with newlines between the case statement and its implementation follows standard Swift style conventions and will produce cleaner generated code.


68-68: Proper spacing for let binding

Adding trailing space to the let keyword ensures consistent spacing in the generated pattern binding. This is a small but important detail for code formatting consistency.

README.md (1)

3-19: Great documentation additions!

The README now provides clear information about the package purpose, compatibility, status, and installation instructions. This will be very helpful for potential users.

.github/workflows/release.yml (1)

20-20: Minor YAML formatting improvement

This formatting change ensures the file ends with a newline, which is a good practice for text files.

Package.resolved (1)

2-2: Dependency update to stable version

The update to the principle dependency from version 0.0.3 to 1.0.0 suggests it has reached a stable state. This is a good practice for version management.

Also applies to: 9-10

.swiftlint.yml (2)

169-170: Good SwiftLint configuration improvement

Configuring line length checks to ignore comments allows for more detailed documentation without triggering warnings, which is a common best practice.


198-198: Improved regex pattern for custom rule

Changing the pattern from (?!\\n*\\}) to (?!\\s*\\}) makes the rule more flexible by accepting any whitespace characters before a closing brace, not just newlines.

Package.swift (1)

25-25: Major dependency version upgrade

Updating the Principle dependency from 0.0.1 to 1.0.0 suggests a stable API with potential breaking changes. Ensure your code accommodates any breaking changes in the Principle 1.0.0 API.

Sources/PrincipleMacros/Imports.swift (1)

9-13: Documentation visibility improvement

Adding @_documentation(visibility: private) to these exported imports is a good practice that keeps your public API documentation clean while still allowing internal code to use these modules freely.

Note that the @_ prefix indicates a compiler-internal attribute that may change in future Swift versions.

.github/workflows/pull-request.yml (5)

4-5: Good practice using environment variables

Defining XCODE_VERSION as an environment variable centralizes this configuration and makes future updates easier to manage.


8-12: Well-structured job organization with outputs

Renaming the job to "prepare" and adding structured outputs improves workflow organization and readability. The outputs for platforms and scheme enable the matrix strategy in the dependent job.


27-52: Clever dynamic extraction of platforms and scheme

This approach dynamically determines which platforms to test on by parsing the package manifest, and intelligently selects the appropriate scheme. This makes the workflow more maintainable and adaptable to changes in package configuration.


53-91: Excellent cross-platform testing strategy

The matrix strategy ensures comprehensive testing across all supported platforms with platform-specific configurations. The conditional steps and destination mapping are well-implemented.


92-110: Appropriate build and test commands for each platform

The workflow correctly differentiates between using Swift Package Manager for macOS and Xcode for other platforms, using the appropriate commands and parameters for each.

@@ -1,17 +1,17 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.1
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Swift Tools Version Upgrade Impact

Upgrading from Swift 6.0 to 6.1 will require contributors and users to update their Swift toolchain. Ensure this aligns with your adoption timeline and that any new Swift 6.1 features you're using are documented.

🧰 Tools
🪛 SwiftLint (0.57.0)

[Warning] 1-1: Header comments should be consistent with project patterns

(file_header)

Comment on lines +9 to +14
.macOS(.v15),
.macCatalyst(.v18),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Very restrictive platform requirements

The platform requirements have increased significantly - most by 2 major versions. This will exclude users on older OS versions and potentially reduce your user base considerably.

Consider whether these high minimum requirements are necessary for your functionality, or if you could support a wider range of devices with lower minimums.

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 (5)
.github/workflows/release.yml (2)

23-35: Verify changes step – Error handling and robustness.
The new "Verify changes" step compares the current and previous major versions to decide on running diagnostics for API-breaking changes. Note that the extraction of previous_tag using

git tag --sort=-v:refname | head -n 2 | tail -n 1

may produce an empty result if there aren’t at least two tags available. Consider adding a check for an empty previous_tag to avoid running diagnostics with an invalid value.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 33-33: trailing spaces

(trailing-spaces)


33-33: Remove trailing whitespace.
There appear to be trailing spaces on line 33. Removing them will clean up the YAML format and satisfy YAML linting rules.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 33-33: trailing spaces

(trailing-spaces)

.github/workflows/pull-request.yml (3)

18-24: Installation of mise tool.
The "Setup mise" step downloads and installs the mise tool using curl. Consider pinning to a specific version or verifying the installation hash to improve reproducibility and security.


34-52: Scheme extraction logic.
The logic to select a scheme by listing schemes via xcodebuild -list and then checking for patterns is effective. If there are multiple matching schemes or if the naming convention evolves, consider making this more robust (for example, by adding more detailed logging or handling ambiguous cases).


65-91: Destination mapping for various platforms.
The "Map destinations" step effectively uses a case statement to specify simulator destinations for non-macos platforms. It covers common platforms (iOS, macOS Catalyst, tvOS, visionOS, watchOS). Consider logging additional context if an unknown platform is encountered, or providing a fallback rather than merely exiting, depending on your desired behavior. Also, ensure that the matrix platform names match exactly what the case statement expects.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1cc61f and b38a698.

📒 Files selected for processing (2)
  • .github/workflows/pull-request.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/release.yml

[error] 33-33: trailing spaces

(trailing-spaces)

🔇 Additional comments (10)
.github/workflows/release.yml (2)

12-12: Using the latest checkout action version.
The step using actions/checkout@v4 is correctly placed and ensures the repository is checked out before other steps run.


17-21: Draft release step review.
The extraction of current_tag using parameter expansion and the use of gh release create with the --draft flag look correct. Please verify that your GitHub CLI version supports the --draft flag and that the command behaves as intended in all tag scenarios.

.github/workflows/pull-request.yml (8)

4-6: Define explicit Xcode version.
Setting XCODE_VERSION: "16.3" in the environment helps ensure consistency across jobs. This explicit declaration is clear and appropriate.


8-12: Outputs declaration in the 'prepare' job.
The outputs platforms and scheme are well defined from the respective steps. Ensure that the steps referenced here reliably provide the expected outputs for downstream jobs.


15-16: Xcode setup in the 'prepare' job.
The step correctly uses sudo xcode-select to point to the specified Xcode version. Make sure that the Xcode version directory matches the runner’s installed versions.


27-33: Extract platforms step verification.
Extracting platforms using swift package dump-package piped to jq is a neat solution. Just ensure that if the package has no defined platforms, the step handles such cases gracefully.


53-60: Matrix configuration in 'build-and-test' job.
The job correctly depends on prepare and uses a matrix strategy based on dynamically extracted platforms. This modular and dynamic configuration is well executed.


61-64: Consistent setup in separate jobs.
Repeating the checkout and Xcode setup steps in the build-and-test job is acceptable due to job isolation. This ensures a clean environment for building and testing.


92-102: Build steps differentiation.
The separation between building with Swift Package Manager (for macos) and using Xcode (for other platforms) is clear and well structured. The use of xcbeautify for cleaner logs is a nice touch.


103-113: Test steps differentiation.
Similarly, the test steps are split based on the platform. This conditional execution ensures that the correct build tool is used without mixing concerns.

@NSFatalError NSFatalError merged commit f3c3d13 into main Apr 5, 2025
7 of 8 checks passed
@NSFatalError NSFatalError deleted the feature/docs branch April 5, 2025 16:49
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