refactor: extract shared markdown builders from rules generation strategies #72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
SingleFileRulesStrategy
andMultiFileRulesStrategy
classes contained significant code duplication for generating markdown content. Both strategies independently implemented:This duplication made the codebase harder to maintain and increased the risk of inconsistencies when making changes.
Solution
Extracted common markdown generation logic into a shared utility module
rulesMarkdownBuilders.ts
containing:Shared Functions
createProjectMarkdown()
- Generates consistent project headerscreateEmptyStateMarkdown()
- Creates empty state messagesgenerateLibraryContent()
- Formats individual library rulesrenderLibrarySection()
- Renders complete library sections with headersgenerateLibrarySections()
- Builds all library sections organized by layer/stackPROJECT_FILE_CONFIG
- Centralizes default file configurationChanges Made
SingleFileRulesStrategy
to use shared utilities (removed ~40 lines)MultiFileRulesStrategy
to use shared utilities (removed ~20 lines)Benefits
✅ Eliminates ~60 lines of duplicate code
✅ Ensures consistent formatting across all strategies
✅ Simplifies adding new strategies - just import and use shared functions
✅ Makes copy changes easier - update in one place, affects all strategies
✅ Improves maintainability - single source of truth for markdown generation
✅ Better testability - shared functions can be unit tested independently
Testing
All existing tests pass without modification, confirming this is a pure refactoring with no behavior changes.
npm run test ✅ npm run lint:check ✅
🤖 Generated with Claude Code