pub struct FileDebtMetrics {Show 13 fields
pub path: PathBuf,
pub total_lines: usize,
pub function_count: usize,
pub class_count: usize,
pub avg_complexity: f64,
pub max_complexity: u32,
pub total_complexity: u32,
pub coverage_percent: f64,
pub uncovered_lines: usize,
pub god_object_indicators: GodObjectIndicators,
pub function_scores: Vec<f64>,
pub god_object_type: Option<GodObjectType>,
pub file_type: Option<FileType>,
}Fields§
§path: PathBuf§total_lines: usize§function_count: usize§class_count: usize§avg_complexity: f64§max_complexity: u32§total_complexity: u32§coverage_percent: f64§uncovered_lines: usize§god_object_indicators: GodObjectIndicators§function_scores: Vec<f64>§god_object_type: Option<GodObjectType>The specific type of god object detected (if any).
This field contains the classification of god object patterns:
GodModule: A module with too many related structs/types that should be splitTraditionalGodObject: A single class/struct with too many responsibilitiesBoilerplate: Repetitive code that should be macro-ified (NOT a god object)Registry: A lookup table or mapping structure (NOT a god object)
This type is used to determine the appropriate recommendation, following this precedence:
- Boilerplate → recommend macros/codegen
- Registry → recommend keeping as-is or data-driven approach
- TraditionalGodObject → recommend extracting classes/modules
- GodModule → recommend splitting into multiple modules
- None → use general refactoring recommendations based on size/complexity
file_type: Option<FileType>File type classification for context-aware thresholds (spec 135)
Implementations§
Source§impl FileDebtMetrics
impl FileDebtMetrics
pub fn calculate_score(&self) -> f64
Sourcepub fn get_score_factors(&self) -> FileScoreFactors
pub fn get_score_factors(&self) -> FileScoreFactors
Extract individual scoring factors for display purposes.
This method decomposes the opaque score calculation from calculate_score()
into individual factors that can be shown to users for transparency.
§Returns
FileScoreFactors containing:
- All 6 multiplicative factors (size, complexity, coverage, density, god object, function)
- Basis values used to calculate each factor
- Contextual information for display (e.g., whether flagged as god object)
§Example
let mut metrics = FileDebtMetrics::default();
metrics.total_lines = 400;
metrics.coverage_percent = 0.75;
let factors = metrics.get_score_factors();
println!("Coverage factor: {:.2} ({:.0}% coverage)",
factors.coverage_factor,
factors.coverage_percent * 100.0);Sourcepub fn generate_recommendation(&self) -> String
pub fn generate_recommendation(&self) -> String
Generate a recommendation for addressing this file’s technical debt.
This function uses a precedence-based strategy to select the most appropriate recommendation type, checking patterns in this order:
-
Boilerplate Pattern (highest priority)
- Detected when file has many repetitive trait implementations
- Recommendation: Use macros or code generation to reduce repetition
- Example: ripgrep’s flags/defs.rs with 888 Flag trait implementations
-
Registry Pattern
- Detected when file is primarily a lookup table or data mapping
- Recommendation: Keep as-is or convert to data-driven approach
- Example: Error code registries, configuration tables
-
God Object
- Detected when file has too many responsibilities (via god_object_indicators)
- Recommendation: Split into multiple focused modules
- Context-specific advice based on file type (parser, cache, analyzer, etc.)
-
Large File (>500 lines)
- Recommendation: Extract complex functions to reduce size
-
Complex Functions (avg complexity >10)
- Recommendation: Simplify logic, extract helper functions
-
Low Coverage (<50%)
- Recommendation: Add tests for uncovered code
The precedence ensures that boilerplate files don’t get incorrectly flagged as god objects requiring module splitting.
Trait Implementations§
Source§impl Clone for FileDebtMetrics
impl Clone for FileDebtMetrics
Source§fn clone(&self) -> FileDebtMetrics
fn clone(&self) -> FileDebtMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FileDebtMetrics
impl Debug for FileDebtMetrics
Source§impl Default for FileDebtMetrics
impl Default for FileDebtMetrics
Source§impl<'de> Deserialize<'de> for FileDebtMetrics
impl<'de> Deserialize<'de> for FileDebtMetrics
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for FileDebtMetrics
impl RefUnwindSafe for FileDebtMetrics
impl Send for FileDebtMetrics
impl Sync for FileDebtMetrics
impl Unpin for FileDebtMetrics
impl UnwindSafe for FileDebtMetrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more