@@ -17,11 +17,11 @@ use crate::raw;
1717/// e.g., "src/foo/bar.py" -> ["", "src", "src/foo"]
1818fn get_parent_paths ( file_path : & str ) -> Vec < String > {
1919 let mut paths = vec ! [ "" . to_string( ) ] ; // Root is always included
20-
20+
2121 if let Some ( last_slash) = file_path. rfind ( '/' ) {
2222 let dir_part = & file_path[ ..last_slash] ;
2323 let mut current = String :: new ( ) ;
24-
24+
2525 for component in dir_part. split ( '/' ) {
2626 if !component. is_empty ( ) {
2727 if current. is_empty ( ) {
@@ -33,7 +33,7 @@ fn get_parent_paths(file_path: &str) -> Vec<String> {
3333 }
3434 }
3535 }
36-
36+
3737 paths
3838}
3939
@@ -109,7 +109,9 @@ impl<'py> IntoPyObject<'py> for CyclomaticResult {
109109 detailed. set_item ( name, cls. into_pyobject ( py) ?) ?;
110110 }
111111
112- let total = CyclomaticTotal { complexity : self . total_complexity } ;
112+ let total = CyclomaticTotal {
113+ complexity : self . total_complexity ,
114+ } ;
113115 dict. set_item ( "detailed" , detailed) ?;
114116 dict. set_item ( "total" , total. into_pyobject ( py) ?) ?;
115117 Ok ( dict)
@@ -221,7 +223,7 @@ struct AggregatedCyclomaticResult {
221223
222224#[ derive( Debug , Clone , IntoPyObject ) ]
223225struct AggregatedCyclomaticTotal {
224- complexity : f64 , // Mean of complexities
226+ complexity : f64 , // Mean of complexities
225227}
226228
227229/// Aggregated halstead metrics for a directory
@@ -253,8 +255,8 @@ struct AggregatedMaintainabilityResult {
253255
254256#[ derive( Debug , Clone , IntoPyObject ) ]
255257struct AggregatedMaintainabilityTotal {
256- mi : f64 , // Mean of MI values
257- rank : String , // Mode of ranks
258+ mi : f64 , // Mean of MI values
259+ rank : String , // Mode of ranks
258260}
259261
260262/// Aggregate results for a directory
@@ -272,44 +274,48 @@ fn compute_aggregates(
272274 directories : & HashSet < String > ,
273275) -> HashMap < String , DirectoryAggregate > {
274276 let mut aggregates = HashMap :: new ( ) ;
275-
277+
276278 for dir in directories {
277279 // Collect all file paths that belong to this directory
278- let matching_files: Vec < & String > = file_results. keys ( )
280+ let matching_files: Vec < & String > = file_results
281+ . keys ( )
279282 . filter ( |path| {
280283 if dir. is_empty ( ) {
281284 true // Root matches all
282285 } else {
283- path. starts_with ( dir) &&
284- ( path. len ( ) == dir. len ( ) || path. chars ( ) . nth ( dir. len ( ) ) == Some ( '/' ) )
286+ path. starts_with ( dir)
287+ && ( path. len ( ) == dir. len ( ) || path. chars ( ) . nth ( dir. len ( ) ) == Some ( '/' ) )
285288 }
286289 } )
287290 . collect ( ) ;
288-
291+
289292 if matching_files. is_empty ( ) {
290293 continue ;
291294 }
292-
295+
293296 // Aggregate raw metrics (all use sum)
294297 let raw_agg = aggregate_raw_metrics ( file_results, & matching_files) ;
295-
298+
296299 // Aggregate cyclomatic (uses mean)
297300 let cyclomatic_agg = aggregate_cyclomatic_metrics ( file_results, & matching_files) ;
298-
301+
299302 // Aggregate halstead (all use sum)
300303 let halstead_agg = aggregate_halstead_metrics ( file_results, & matching_files) ;
301-
304+
302305 // Aggregate maintainability (mi uses mean, rank uses mode)
303306 let maintainability_agg = aggregate_maintainability_metrics ( file_results, & matching_files) ;
304-
305- aggregates. insert ( dir. clone ( ) , DirectoryAggregate {
306- raw : raw_agg,
307- cyclomatic : cyclomatic_agg,
308- halstead : halstead_agg,
309- maintainability : maintainability_agg,
310- } ) ;
307+
308+ aggregates. insert (
309+ dir. clone ( ) ,
310+ DirectoryAggregate {
311+ raw : raw_agg,
312+ cyclomatic : cyclomatic_agg,
313+ halstead : halstead_agg,
314+ maintainability : maintainability_agg,
315+ } ,
316+ ) ;
311317 }
312-
318+
313319 aggregates
314320}
315321
@@ -319,7 +325,7 @@ fn aggregate_raw_metrics(
319325) -> Option < AggregatedRawResult > {
320326 let mut totals: HashMap < String , i64 > = HashMap :: new ( ) ;
321327 let mut has_data = false ;
322-
328+
323329 for path in matching_files {
324330 if let Some ( FileAnalysisResult :: Success { raw : Some ( raw) , .. } ) = file_results. get ( * path) {
325331 has_data = true ;
@@ -328,7 +334,7 @@ fn aggregate_raw_metrics(
328334 }
329335 }
330336 }
331-
337+
332338 if has_data {
333339 Some ( AggregatedRawResult { total : totals } )
334340 } else {
@@ -341,13 +347,17 @@ fn aggregate_cyclomatic_metrics(
341347 matching_files : & [ & String ] ,
342348) -> Option < AggregatedCyclomaticResult > {
343349 let mut complexities: Vec < i64 > = Vec :: new ( ) ;
344-
350+
345351 for path in matching_files {
346- if let Some ( FileAnalysisResult :: Success { cyclomatic : Some ( cc) , .. } ) = file_results. get ( * path) {
352+ if let Some ( FileAnalysisResult :: Success {
353+ cyclomatic : Some ( cc) ,
354+ ..
355+ } ) = file_results. get ( * path)
356+ {
347357 complexities. push ( cc. total_complexity ) ;
348358 }
349359 }
350-
360+
351361 if complexities. is_empty ( ) {
352362 None
353363 } else {
@@ -372,9 +382,13 @@ fn aggregate_halstead_metrics(
372382 let mut difficulty_sum: f64 = 0.0 ;
373383 let mut effort_sum: f64 = 0.0 ;
374384 let mut has_data = false ;
375-
385+
376386 for path in matching_files {
377- if let Some ( FileAnalysisResult :: Success { halstead : Some ( hal) , .. } ) = file_results. get ( * path) {
387+ if let Some ( FileAnalysisResult :: Success {
388+ halstead : Some ( hal) ,
389+ ..
390+ } ) = file_results. get ( * path)
391+ {
378392 has_data = true ;
379393 h1_sum += hal. total . h1 as i64 ;
380394 h2_sum += hal. total . h2 as i64 ;
@@ -387,7 +401,7 @@ fn aggregate_halstead_metrics(
387401 effort_sum += hal. total . effort ;
388402 }
389403 }
390-
404+
391405 if has_data {
392406 Some ( AggregatedHalsteadResult {
393407 total : AggregatedHalsteadTotal {
@@ -413,14 +427,18 @@ fn aggregate_maintainability_metrics(
413427) -> Option < AggregatedMaintainabilityResult > {
414428 let mut mi_values: Vec < f64 > = Vec :: new ( ) ;
415429 let mut rank_counts: HashMap < String , usize > = HashMap :: new ( ) ;
416-
430+
417431 for path in matching_files {
418- if let Some ( FileAnalysisResult :: Success { maintainability : Some ( mi) , .. } ) = file_results. get ( * path) {
432+ if let Some ( FileAnalysisResult :: Success {
433+ maintainability : Some ( mi) ,
434+ ..
435+ } ) = file_results. get ( * path)
436+ {
419437 mi_values. push ( mi. total . mi ) ;
420438 * rank_counts. entry ( mi. total . rank . clone ( ) ) . or_insert ( 0 ) += 1 ;
421439 }
422440 }
423-
441+
424442 if mi_values. is_empty ( ) {
425443 None
426444 } else {
@@ -431,7 +449,7 @@ fn aggregate_maintainability_metrics(
431449 . max_by_key ( |( _, count) | * count)
432450 . map ( |( rank, _) | rank)
433451 . unwrap_or_else ( || "A" . to_string ( ) ) ;
434-
452+
435453 Some ( AggregatedMaintainabilityResult {
436454 total : AggregatedMaintainabilityTotal {
437455 mi : mean_mi,
@@ -687,11 +705,11 @@ pub fn analyze_files_parallel<'py>(
687705 let include_maintainability = operators. iter ( ) . any ( |o| o == "maintainability" ) ;
688706
689707 // Phase 1: Parallel file analysis (GIL released)
690- let ( analysis_results, directories) : ( HashMap < String , FileAnalysisResult > , HashSet < String > ) =
708+ let ( analysis_results, directories) : ( HashMap < String , FileAnalysisResult > , HashSet < String > ) =
691709 py. detach ( || {
692710 // Collect all directory paths first
693711 let dirs = collect_all_directories ( & paths) ;
694-
712+
695713 // Analyze files in parallel
696714 let results: HashMap < String , FileAnalysisResult > = paths
697715 . par_iter ( )
@@ -720,7 +738,7 @@ pub fn analyze_files_parallel<'py>(
720738 ( path. clone ( ) , result)
721739 } )
722740 . collect ( ) ;
723-
741+
724742 ( results, dirs)
725743 } ) ;
726744
0 commit comments