refactor: extract shared markdown builders from rules generation strategies#72
Closed
mkczarkowski wants to merge 1 commit intomasterfrom
Closed
refactor: extract shared markdown builders from rules generation strategies#72mkczarkowski wants to merge 1 commit intomasterfrom
mkczarkowski wants to merge 1 commit intomasterfrom
Conversation
…tegies Refactored SingleFileRulesStrategy and MultiFileRulesStrategy to eliminate code duplication by extracting common markdown generation logic into a shared utility module. ## Problem Both strategy classes duplicated significant amounts of code for: - Project header generation - Empty state messaging - Library content formatting - Section structure rendering ## Solution Created `rulesMarkdownBuilders.ts` with reusable functions: - `createProjectMarkdown()` - Generates project header - `createEmptyStateMarkdown()` - Creates empty state message - `generateLibraryContent()` - Formats individual library rules - `renderLibrarySection()` - Renders complete library section - `generateLibrarySections()` - Builds all library sections - `PROJECT_FILE_CONFIG` - Centralizes default configuration ## Benefits - Eliminates ~60 lines of duplicate code - Ensures consistent formatting across strategies - Simplifies future strategy additions - Makes copy changes easier to manage - Improves maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
✅ All checks have passed successfully!
Coverage reports have been uploaded as artifacts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
SingleFileRulesStrategyandMultiFileRulesStrategyclasses 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.tscontaining: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
SingleFileRulesStrategyto use shared utilities (removed ~40 lines)MultiFileRulesStrategyto 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