Skip to content

Conversation

mkczarkowski
Copy link
Collaborator

@mkczarkowski mkczarkowski commented Sep 29, 2025

Problem

The SingleFileRulesStrategy and MultiFileRulesStrategy classes contained significant code duplication for generating markdown content. Both strategies independently implemented:

  • Project header creation
  • Empty state messaging
  • Library content formatting
  • Section structure rendering

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 headers
  • createEmptyStateMarkdown() - Creates empty state messages
  • generateLibraryContent() - Formats individual library rules
  • renderLibrarySection() - Renders complete library sections with headers
  • generateLibrarySections() - Builds all library sections organized by layer/stack
  • PROJECT_FILE_CONFIG - Centralizes default file configuration

Changes Made

  • Refactored SingleFileRulesStrategy to use shared utilities (removed ~40 lines)
  • Refactored MultiFileRulesStrategy to use shared utilities (removed ~20 lines)
  • Created new shared module with well-documented, reusable functions

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

…egies

Extract common scaffolding from Single and Multi file strategies into reusable builders module. This reduces code duplication and ensures consistent formatting across both strategies.

Key changes:
- Created markdown-builders module with shared utilities
- Extracted project header, empty state, and library section rendering
- Unified iteration logic over layer/stack/library structure
- Simplified both strategies to use shared builders

Benefits:
- Guarantees consistent formatting across strategies
- Reduces effort when adding new strategies
- Single source of truth for markdown generation logic
- Easier maintenance and testing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

✅ All checks have passed successfully!

  • Lint: ✅
  • Unit Tests: ✅
  • E2E Tests: ✅

Coverage reports have been uploaded as artifacts.

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