@@ -319,6 +319,26 @@ fn parse_json_message(json_message: &str, krate: &Crate) -> ClippyWarning {
319319 }
320320}
321321
322+ /// Generate a short list of occuring lints-types and their count
323+ fn gather_stats ( clippy_warnings : & [ ClippyWarning ] ) -> String {
324+ // count lint type occurrences
325+ let mut counter: HashMap < & String , usize > = HashMap :: new ( ) ;
326+ clippy_warnings
327+ . iter ( )
328+ . for_each ( |wrn| * counter. entry ( & wrn. linttype ) . or_insert ( 0 ) += 1 ) ;
329+
330+ // collect into a tupled list for sorting
331+ let mut stats: Vec < ( & & String , & usize ) > = counter. iter ( ) . map ( |( lint, count) | ( lint, count) ) . collect ( ) ;
332+ // sort by "000{count} {clippy::lintname}"
333+ // to not have a lint with 200 and 2 warnings take the same spot
334+ stats. sort_by_key ( |( lint, count) | format ! ( "{:0>4}, {}" , count, lint) ) ;
335+
336+ stats
337+ . iter ( )
338+ . map ( |( lint, count) | format ! ( "{} {}\n " , lint, count) )
339+ . collect :: < String > ( )
340+ }
341+
322342/// lintchecks `main()` function
323343pub fn run ( clap_config : & ArgMatches ) {
324344 let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" ) ;
@@ -380,7 +400,8 @@ pub fn run(clap_config: &ArgMatches) {
380400 . collect ( )
381401 } ;
382402
383- // generate some stats:
403+ // generate some stats
404+ let stats_formatted = gather_stats ( & clippy_warnings) ;
384405
385406 // grab crashes/ICEs, save the crate name and the ice message
386407 let ices: Vec < ( & String , & String ) > = clippy_warnings
@@ -389,23 +410,6 @@ pub fn run(clap_config: &ArgMatches) {
389410 . map ( |w| ( & w. crate_name , & w. message ) )
390411 . collect ( ) ;
391412
392- // count lint type occurrences
393- let mut counter: HashMap < & String , usize > = HashMap :: new ( ) ;
394- clippy_warnings
395- . iter ( )
396- . for_each ( |wrn| * counter. entry ( & wrn. linttype ) . or_insert ( 0 ) += 1 ) ;
397-
398- // collect into a tupled list for sorting
399- let mut stats: Vec < ( & & String , & usize ) > = counter. iter ( ) . map ( |( lint, count) | ( lint, count) ) . collect ( ) ;
400- // sort by "000{count} {clippy::lintname}"
401- // to not have a lint with 200 and 2 warnings take the same spot
402- stats. sort_by_key ( |( lint, count) | format ! ( "{:0>4}, {}" , count, lint) ) ;
403-
404- let stats_formatted: String = stats
405- . iter ( )
406- . map ( |( lint, count) | format ! ( "{} {}\n " , lint, count) )
407- . collect :: < String > ( ) ;
408-
409413 let mut all_msgs: Vec < String > = clippy_warnings. iter ( ) . map ( |warning| warning. to_string ( ) ) . collect ( ) ;
410414 all_msgs. sort ( ) ;
411415 all_msgs. push ( "\n \n \n \n Stats\n \n " . into ( ) ) ;
0 commit comments