Skip to content

refactor: modularize mtlog-analyzer into focused single-responsibility modules#28

Merged
willibrandon merged 3 commits intomainfrom
refactor/analyzer-modularization
Aug 8, 2025
Merged

refactor: modularize mtlog-analyzer into focused single-responsibility modules#28
willibrandon merged 3 commits intomainfrom
refactor/analyzer-modularization

Conversation

@willibrandon
Copy link
Owner

Description

Refactored the monolithic analyzer.go file (1,777 lines) into 12 focused, single-responsibility modules to improve code organization, maintainability, and test-ability. Each module now handles a specific aspect of the analysis, with all files kept under 410 lines for better readability.

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Documentation update

Checklist

  • Tests pass (go test ./...)
  • Linter passes (golangci-lint run)
  • Benchmarks checked (if performance-related)
  • Documentation updated (if needed)
  • Zero-allocation promise maintained (if applicable)

Additional notes

Split monolithic analyzer.go (1,777 lines) into 12 focused modules:
- ast_walker.go (161 lines) - AST traversal utilities
- cache.go (94 lines) - template caching
- config.go (32 lines) - configuration types
- context_checks.go (94 lines) - context usage validation
- coordinator.go (53 lines) - check orchestration
- diagnostics.go (60 lines) - diagnostic constants
- error_checks.go (290 lines) - error logging validation
- property_checks.go (228 lines) - property naming/capturing
- quickfix.go (407 lines) - suggested fix generation
- template_checks.go (258 lines) - template argument validation
- validation.go (105 lines) - helper validation functions
- analyzer.go reduced to 128 lines
@willibrandon willibrandon added enhancement New feature or request tooling Development tools, build systems, and analyzers mtlog-analyzer Static analysis tool for detecting mtlog usage issues labels Aug 8, 2025
@willibrandon willibrandon self-assigned this Aug 8, 2025
@willibrandon willibrandon requested a review from Copilot August 8, 2025 05:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This refactoring modularizes the monolithic analyzer.go file (1,777 lines) into 12 focused, single-responsibility modules, improving code organization, maintainability, and testability while keeping all files under 410 lines for better readability.

  • Modularized analysis functionality into focused files with clear responsibilities
  • Maintained all existing functionality while improving code organization
  • Added proper error handling in test files for flag setting operations

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
analyzer.go Main entry point, reduced from 1,777 lines to 128 lines by extracting functionality
validation.go Property extraction and format specifier validation logic
template_checks.go Template argument validation and suggested fixes generation
suppression_test.go Fixed unchecked error from flag setting operations
quickfix.go Type checking helpers and context key constant generation utilities
property_checks.go Property naming and capturing usage validation logic
killswitch_test.go Fixed unchecked error from flag setting operations
error_checks.go Error logging validation with scope-based error variable detection
diagnostics.go Centralized diagnostic reporting with ID and severity management
coordinator.go Main coordination logic for running all applicable checks
context_checks.go Context usage pattern validation for ForContext and PushProperty
config.go Configuration management with flag extraction helpers
cache.go Template caching and source file reading utilities
ast_walker.go AST traversal and mtlog call detection logic

- Fix comment in context_checks.go to clarify package vs method calls
- Create templateMismatchContext struct to reduce function parameters from 6 to 1
- Document uniqueConstNameMaxAttempts constant with rationale for value 100
@willibrandon willibrandon merged commit 8a8aa42 into main Aug 8, 2025
23 checks passed
@willibrandon willibrandon deleted the refactor/analyzer-modularization branch August 8, 2025 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request mtlog-analyzer Static analysis tool for detecting mtlog usage issues tooling Development tools, build systems, and analyzers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor analyzer.go into smaller, focused modules

1 participant