feat: new usage rendering mechanism - #161
Conversation
WalkthroughThis change introduces a new Changes
Sequence Diagram(s)sequenceDiagram
participant CLI
participant RendererDecorators
participant PluginContext
participant Renderer
CLI->>RendererDecorators: Instantiate
CLI->>PluginContext: Instantiate with RendererDecorators
PluginContext->>RendererDecorators: Add renderer decorators (optional)
CLI->>RendererDecorators: Get header/usage/errors renderer
RendererDecorators->>Renderer: Compose decorators around base renderer
CLI->>Renderer: Render output using composed renderer
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/gunshi/test/utils.ts (1)
141-174: Comprehensive mock implementation with minor type safety concerns.The mock provides good coverage of the
CommandContextinterface. However, consider improving the translate function implementation for better type safety.Consider this more type-safe approach for the translate function:
- // eslint-disable-next-line unicorn/prefer-native-coercion-functions, @typescript-eslint/no-explicit-any - translate: ((key: any) => String(key)) as CommandContext['translate'] + translate: (key: string, values?: Record<string, unknown>) => keyThis removes the need for ESLint disables and provides clearer typing.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (8)
eslint.config.ts(1 hunks)packages/gunshi/src/cli.ts(6 hunks)packages/gunshi/src/decorators.test.ts(1 hunks)packages/gunshi/src/decorators.ts(1 hunks)packages/gunshi/src/plugin.test.ts(2 hunks)packages/gunshi/src/plugin.ts(3 hunks)packages/gunshi/src/types.ts(1 hunks)packages/gunshi/test/utils.ts(2 hunks)
🔇 Additional comments (22)
eslint.config.ts (1)
36-37: LGTM! Improved glob pattern precision.The updated patterns correctly match test files at any depth within
srcdirectories. The original patterns would miss nested test files due to incorrect glob syntax.packages/gunshi/test/utils.ts (1)
13-17: LGTM! Proper import expansion.The addition of
CommandContextimport supports the new mock function implementation.packages/gunshi/src/plugin.test.ts (3)
6-11: Well-structured mock setup.The mocking isolates the default renderers effectively, allowing focused testing of the decoration behavior.
15-40: Consistent integration with new decorator system.All existing tests are properly updated to use the
RendererDecoratorsconstructor parameter, maintaining test functionality while adapting to the new architecture.
43-96: Comprehensive coverage of decorator functionality.The new test suites effectively verify that each decorator type (header, usage, validation errors) works correctly. The tests properly:
- Use async/await for decoration testing
- Verify decorated output contains expected modifications
- Pass appropriate parameters (including error for validation decorators)
- Use consistent mock contexts
packages/gunshi/src/decorators.test.ts (4)
1-11: Excellent test setup with proper mocking.The mock setup isolates the default renderers effectively, enabling focused testing of the decorator chain behavior.
12-42: Thorough verification of default behavior.These tests properly verify that the system works correctly when no decorators are applied, providing a solid baseline for decorator functionality testing.
44-78: Comprehensive decorator application testing.The tests effectively verify both single and multiple decorator scenarios, including the correct application order. The assertion on line 77 clearly demonstrates that decorators are applied in the expected sequence.
80-159: Excellent coverage of advanced scenarios.This section covers critical aspects including:
- Async decorator handling with proper timing
- Context parameter passing verification
- Error parameter handling for validation decorators
- Exception propagation from decorators
- Edge case testing with empty decorator chains
The test implementations are robust and provide confidence in the decorator system's reliability.
packages/gunshi/src/plugin.ts (3)
34-36: LGTM! Constructor properly initializes decorator dependency.The constructor correctly accepts and stores the
RendererDecoratorsinstance, establishing proper dependency injection for the new rendering system.
51-59: Good validation logic for global options.The validation correctly prevents empty option names and duplicate registrations, which helps maintain data integrity.
65-83: Clean delegation pattern for decorator methods.The three decorator methods properly delegate to the internal
RendererDecoratorsinstance, maintaining good separation of concerns and encapsulation.packages/gunshi/src/types.ts (2)
484-494: Well-designed generic decorator type.The
RendererDecorator<T>type correctly captures the decorator pattern with proper typing for the base renderer function and return type. The generic parameter allows reuse across different renderer types.
496-508: Appropriate specialized type for validation error decorators.The
ValidationErrorsDecoratortype correctly extends the decorator pattern to include theAggregateErrorparameter, maintaining type safety for validation error rendering.packages/gunshi/src/cli.ts (4)
38-40: Clean integration of decorator system.The
RendererDecoratorsinstance is properly created and passed to thePluginContext, establishing the foundation for the new rendering mechanism.
156-169: Proper renderer resolution with fallback logic.The function correctly prioritizes environment overrides while falling back to decorated renderers from the decorators instance, maintaining backward compatibility.
175-189: Consistent header rendering pattern.The header rendering follows the same pattern as usage rendering, ensuring consistency in the decorator system integration.
191-201: Validation error rendering maintains same pattern.The validation error rendering correctly follows the established pattern of environment override priority with decorator fallback.
packages/gunshi/src/decorators.ts (4)
14-29: Well-encapsulated decorator storage.The private arrays and public add methods provide clean encapsulation for managing decorators of different types. The naming is clear and consistent.
31-37: Clean delegation to shared builder method.The getter methods properly delegate to the shared
#buildRenderermethod, promoting code reuse and consistency.
39-50: Correct composition logic for validation error decorators.The inline composition correctly handles the different signature of validation error decorators, maintaining the proper decorator chain where each decorator wraps the previous renderer.
52-66: Solid decorator composition implementation.The
#buildRenderermethod correctly composes decorators in the right order, where each decorator receives the previous renderer and context. The early return for empty decorators is an efficient optimization.
Deploying gunshi with
|
| Latest commit: |
7d21227
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://60025a3b.gunshi.pages.dev |
| Branch Preview URL: | https://feat-render-usage-on-plugin.gunshi.pages.dev |
Description
Linked Issues
Additional context
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation