11use std:: {
2+ cmp:: Reverse ,
23 fs,
34 path:: Path ,
45 time:: { Duration , SystemTime , UNIX_EPOCH } ,
@@ -38,9 +39,8 @@ const KNOWN_BUNDLE_ARTIFACTS: [&str; 5] = [
3839
3940pub fn analyze_project < P : AsRef < Path > > ( input_path : P ) -> Result < Analysis > {
4041 let project_root = find_project_root ( input_path) ?;
41- let manifest: Value = read_json_if_exists ( project_root. join ( "package.json" ) ) ?. ok_or_else ( || {
42- LegolasError :: PackageJsonMissing ( project_root. display ( ) . to_string ( ) )
43- } ) ?;
42+ let manifest: Value = read_json_if_exists ( project_root. join ( "package.json" ) ) ?
43+ . ok_or_else ( || LegolasError :: PackageJsonMissing ( project_root. display ( ) . to_string ( ) ) ) ?;
4444
4545 let package_manager = detect_package_manager ( & project_root, & manifest) ?;
4646 let frameworks = detect_frameworks ( & project_root, & manifest) ?;
@@ -73,7 +73,10 @@ pub fn analyze_project<P: AsRef<Path>>(input_path: P) -> Result<Analysis> {
7373 duplicate_packages : duplicate_analysis. duplicates ,
7474 lazy_load_candidates,
7575 tree_shaking_warnings,
76- unused_dependency_candidates : build_unused_dependency_candidates ( & manifest, & source_analysis) ,
76+ unused_dependency_candidates : build_unused_dependency_candidates (
77+ & manifest,
78+ & source_analysis,
79+ ) ,
7780 warnings : duplicate_analysis. warnings ,
7881 impact,
7982 metadata : Metadata {
@@ -126,15 +129,17 @@ fn build_heavy_dependency_report(
126129 category : intel. category . to_string ( ) ,
127130 rationale : intel. rationale . to_string ( ) ,
128131 recommendation : intel. recommendation . to_string ( ) ,
129- imported_by : import_info. map ( |item| item. files . clone ( ) ) . unwrap_or_default ( ) ,
132+ imported_by : import_info
133+ . map ( |item| item. files . clone ( ) )
134+ . unwrap_or_default ( ) ,
130135 dynamic_imported_by : import_info
131136 . map ( |item| item. dynamic_files . clone ( ) )
132137 . unwrap_or_default ( ) ,
133138 import_count : import_info. map ( |item| item. files . len ( ) ) . unwrap_or ( 0 ) ,
134139 } ) ;
135140 }
136141
137- heavy_dependencies. sort_by ( |left , right| right . estimated_kb . cmp ( & left . estimated_kb ) ) ;
142+ heavy_dependencies. sort_by_key ( |item| Reverse ( item . estimated_kb ) ) ;
138143 heavy_dependencies
139144}
140145
@@ -151,8 +156,9 @@ fn merged_dependency_entries(manifest: &Value) -> Vec<(String, String)> {
151156 continue ;
152157 } ;
153158
154- if let Some ( ( _, existing_range) ) =
155- entries. iter_mut ( ) . find ( |( existing_name, _) | existing_name == name)
159+ if let Some ( ( _, existing_range) ) = entries
160+ . iter_mut ( )
161+ . find ( |( existing_name, _) | existing_name == name)
156162 {
157163 * existing_range = version_range. to_string ( ) ;
158164 continue ;
@@ -203,13 +209,13 @@ fn build_lazy_load_candidates(
203209 } ) ;
204210 }
205211
206- candidates. sort_by ( |left , right| right . estimated_savings_kb . cmp ( & left . estimated_savings_kb ) ) ;
212+ candidates. sort_by_key ( |item| Reverse ( item . estimated_savings_kb ) ) ;
207213 candidates
208214}
209215
210216fn build_tree_shaking_warnings ( source_analysis : & SourceAnalysis ) -> Vec < TreeShakingWarning > {
211217 let mut warnings = source_analysis. tree_shaking_warnings . clone ( ) ;
212- warnings. sort_by ( |left , right| right . estimated_kb . cmp ( & left . estimated_kb ) ) ;
218+ warnings. sort_by_key ( |item| Reverse ( item . estimated_kb ) ) ;
213219 warnings
214220}
215221
@@ -278,9 +284,7 @@ fn format_iso8601_utc(duration: Duration) -> String {
278284 let minute = ( seconds_of_day % 3_600 ) / 60 ;
279285 let second = seconds_of_day % 60 ;
280286
281- format ! (
282- "{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}.{milliseconds:03}Z"
283- )
287+ format ! ( "{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}.{milliseconds:03}Z" )
284288}
285289
286290fn civil_from_days ( days_since_unix_epoch : i64 ) -> ( i32 , u32 , u32 ) {
0 commit comments