Ragex.Analysis.Suggestions.Patterns (Ragex v0.3.0)

View Source

Pattern detection for common refactoring opportunities.

Detects 8 patterns:

  1. Extract Function - Long functions, duplicate code blocks
  2. Inline Function - Single-use functions, trivial wrappers
  3. Split Module - God modules, low cohesion
  4. Merge Modules - Similar modules, related functionality
  5. Remove Dead Code - Unused functions, unreachable code
  6. Reduce Coupling - High-coupling modules, circular dependencies
  7. Simplify Complexity - High cyclomatic complexity, deep nesting
  8. Extract Module - Related functions in different modules

Each detector returns suggestions with:

  • Pattern type
  • Confidence score (0.0-1.0)
  • Target location
  • Reason/justification
  • Relevant metrics

Summary

Functions

Returns list of all available pattern types.

Detects a specific pattern in the analysis data.

Functions

all_patterns()

Returns list of all available pattern types.

detect(pattern, analysis_data, opts \\ [])

Detects a specific pattern in the analysis data.

Parameters

  • pattern - Pattern type to detect
  • analysis_data - Analysis data from Suggestions.gather_analysis_data/2
  • opts - Additional options

Returns

  • {:ok, [suggestion]} - List of raw suggestions (not yet scored)
  • {:error, reason} - Error if detection fails