Conversation
|
Review of PR #584: feat(flags): validate config and align docsSummaryThis PR improves the feature-flags plugin by:
Overall, this is a solid improvement that makes the API clearer and prevents runtime errors. However, there are a few concerns about the implementation approach. Code Quality & Best PracticesGood:
Concerns:
Potential Bugs
Performance ConsiderationsNo performance concerns. The validation runs once during config parsing, which is negligible overhead. Security ConcernsNo security issues identified. The validation actually improves security by preventing misconfiguration. Documentation QualityExcellent improvements:
Minor suggestion: /**
* Library configurations: library name -> config
*
* Required in mark mode, should be omitted in shake mode.
* ...
*/
libraries: Record<string, LibraryConfig>;Test CoverageGood coverage:
Missing tests:
Recommendations PriorityHigh Priority:
Medium Priority: Low Priority: Great work on improving the API surface and documentation! The changes make the plugin much easier to use correctly. |
There was a problem hiding this comment.
Pull request overview
This PR improves the feature flags plugin by removing unused configuration options, clarifying mode-specific behavior, and adding configuration validation. The changes align documentation with actual implementation behavior, specifically clarifying that shake mode operates on __SWC_FLAGS__ markers and does not use the libraries configuration, while mark mode requires it.
Changes:
- Removed
excludeFlagsfield from type definitions and documentation (unused feature) - Added runtime configuration validation to ensure required fields are present for each mode
- Added test coverage for configuration validation scenarios
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/feature-flags/types.d.ts | Removed excludeFlags field from both FeatureFlagsConfig and BuildTimeConfig interfaces, added clarification that libraries are required in mark mode but not used in shake mode |
| packages/feature-flags/src/lib.rs | Added validate_feature_flags_config and validate_build_time_config functions to validate required configuration fields based on mode, integrated validation into plugin entry points |
| packages/feature-flags/tests/wasm.test.ts | Added comprehensive validation tests covering missing libraries in mark mode, missing flagValues in shake mode, and empty functions array |
| packages/feature-flags/README.tmpl.md | Removed excludeFlags documentation section, clarified shake mode behavior to emphasize it operates on markers and doesn't use libraries, updated usage examples |
| packages/feature-flags/README.md | Same documentation updates as README.tmpl.md |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for (library, library_config) in &config.libraries { | ||
| if library_config.functions.is_empty() { | ||
| panic!( | ||
| "FeatureFlagsConfig: \"functions\" must not be empty for library \"{}\"", | ||
| library | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
The validation for non-empty functions in libraries should only apply in mark mode, not shake mode. According to the updated documentation, shake mode does not use libraries. This validation block should be moved inside the mark mode branch (after line 17) to prevent incorrect validation errors when a user provides a library config with empty functions in shake mode.
Summary
Testing