Skip to content

Refactor complex files to meet RuboCop standards #60

@cardmagic

Description

@cardmagic

Summary

Several files are currently excluded from RuboCop metrics checks due to their complexity. These could be refactored to meet the standards while maintaining functionality.

Files to Refactor

lib/classifier/extensions/vector.rb

  • SV_decomp method (46 lines, high complexity)
  • Contains nested loops for SVD algorithm
  • Consider extracting helper methods

lib/classifier/lsi/content_node.rb

  • raw_vector_with method (28 lines, high complexity)
  • Multiple conditionals for GSL vs pure Ruby
  • Consider strategy pattern or separate implementations

lib/classifier/lsi.rb

  • build_index method (high ABC size)
  • Complex matrix operations
  • Consider breaking into smaller methods

Goals

RuboCop Compliance

  • Reduce method length to ≤25 lines
  • Reduce ABC size to ≤30
  • Reduce cyclomatic complexity to ≤10

Test Coverage

  • Add unit tests for extracted helper methods
  • Improve branch coverage for GSL vs native paths
  • Target 95%+ line coverage for refactored files

RBS Type Signatures

  • Add/update type signatures in sig/ for refactored methods
  • Ensure new helper methods have proper type annotations
  • Validate with rbs -I sig validate

Other Requirements

  • Maintain 100% backward compatibility
  • Keep performance characteristics
  • Document complex algorithms inline

Approach

  1. Extract helper methods for repeated logic
  2. Use early returns to reduce nesting
  3. Consider strategy pattern for GSL vs native paths
  4. Add inline documentation for complex algorithms
  5. Write tests for new helper methods before refactoring
  6. Update RBS signatures as methods are extracted

Related

Follow-up from #56 (RuboCop integration)

Metadata

Metadata

Assignees

Labels

code-qualityCode style and quality improvementspriority: lowLow priority - nice to have

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions