Skip to content

Commit f89e47d

Browse files
fahchenclaude
andauthored
refactor: modularize codebase and enhance Mix formatter integration (#8)
# Modularize Codebase and Enhance Mix Formatter Integration This PR implements comprehensive refactoring to improve code organization while maintaining the Mix.Tasks.Format plugin integration that allows formatting both pure markdown and embedded markdown in Elixir files. ## Mix.Tasks.Format Integration This formatter works as a **Mix formatter plugin** via `@behaviour Mix.Tasks.Format`: - **Plugin Priority**: When configured, it processes `.ex/.exs` files **BEFORE** the standard `elixir_format` function - **Smart Processing**: Two-phase approach for Elixir files: 1. Formats markdown content in module attributes (`@moduledoc`, `@doc`, etc.) 2. Calls `Code.format_string\!` to ensure proper Elixir code formatting - **File Support**: Handles pure markdown (`.md/.markdown`) AND embedded markdown in Elixir files - **Sigil Support**: Provides `~M` sigil for embedded markdown formatting ## Refactoring Impact - **Main module**: 515 → 313 lines (40% reduction) - **New modules**: 3 focused modules (AstProcessor, PatchBuilder, StringUtils) - **Code duplication**: Eliminated 150+ lines - **Tests**: All pass (13 doctests, 80 tests, 0 failures, 1 skipped) ## Changes by Phase ### ✅ Validator Pattern Matching - Consolidated repetitive validation using shared `validate_atom_choice/3` and `validate_string_choice/3` - Reduced function count from 15 to 8, eliminated 69 duplicate lines ### ✅ AST Processing Module - Extracted `DprintMarkdownFormatter.AstProcessor` for parsing and patch creation - Moved `parse_elixir_source`, `collect_patches_for_doc_attributes`, etc. ### ✅ Control Flow Simplification - Replaced `cond` with pattern matching, combined function heads - Improved error handling consistency ### ✅ Patch Builder Logic - Created `DprintMarkdownFormatter.PatchBuilder` for string replacements - Comprehensive documentation with examples ### ✅ Rust NIF Improvements - Extracted config building functions, reduced duplication by 30+ lines - Cleaner match statements for enum mapping ## Quality Assurance ✅ All tests pass without modification ✅ Full quality checks (Credo, Dialyzer, Cargo fmt/clippy) ✅ No breaking changes to public API ✅ Performance maintained ## Benefits - **Maintainability**: Clear separation of concerns, focused modules - **Developer Experience**: Better organization, comprehensive documentation - **Future-proof**: Modular structure enables easier enhancements --- 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 69119c4 commit f89e47d

13 files changed

Lines changed: 626 additions & 488 deletions

File tree

.formatter.exs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
[
33
plugins: [DprintMarkdownFormatter],
44
import_deps: [:typed_structor],
5-
locals_without_parens: [
6-
custom_function: 1
7-
],
85
inputs: [
96
"{mix,.formatter}.exs",
107
"{config,lib}/**/*.{ex,exs}",

0 commit comments

Comments
 (0)