Skip to content

Conversation

mkczarkowski
Copy link
Collaborator

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

…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>
Copy link

✅ All checks have passed successfully!

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

Coverage reports have been uploaded as artifacts.

@przeprogramowani przeprogramowani deleted the refactor-markdown-builders branch September 24, 2025 10:40
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.

2 participants