diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-02-14 18:59:32 +0100 |
|---|---|---|
| committer | Matthias Krüger <matthias.krueger@famsik.de> | 2021-02-15 22:13:17 +0100 |
| commit | 214d821268628f7637d004c8e6b5eb7b69dd0583 (patch) | |
| tree | 6cc20ff5495b950b89febeb2ba57204ad3b5e257 /clippy_dev | |
| parent | 4856e5f8fc37f1fbe3766a44f1cec9520e208a5a (diff) | |
| download | rust-214d821268628f7637d004c8e6b5eb7b69dd0583.tar.gz rust-214d821268628f7637d004c8e6b5eb7b69dd0583.zip | |
lintcheck: put some code into a gather_stats() function
Diffstat (limited to 'clippy_dev')
| -rw-r--r-- | clippy_dev/src/lintcheck.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/clippy_dev/src/lintcheck.rs b/clippy_dev/src/lintcheck.rs index 45620cc9e63..ce05d4b0887 100644 --- a/clippy_dev/src/lintcheck.rs +++ b/clippy_dev/src/lintcheck.rs @@ -319,6 +319,26 @@ fn parse_json_message(json_message: &str, krate: &Crate) -> ClippyWarning { } } +/// Generate a short list of occuring lints-types and their count +fn gather_stats(clippy_warnings: &[ClippyWarning]) -> String { + // count lint type occurrences + let mut counter: HashMap<&String, usize> = HashMap::new(); + clippy_warnings + .iter() + .for_each(|wrn| *counter.entry(&wrn.linttype).or_insert(0) += 1); + + // collect into a tupled list for sorting + let mut stats: Vec<(&&String, &usize)> = counter.iter().map(|(lint, count)| (lint, count)).collect(); + // sort by "000{count} {clippy::lintname}" + // to not have a lint with 200 and 2 warnings take the same spot + stats.sort_by_key(|(lint, count)| format!("{:0>4}, {}", count, lint)); + + stats + .iter() + .map(|(lint, count)| format!("{} {}\n", lint, count)) + .collect::<String>() +} + /// lintchecks `main()` function pub fn run(clap_config: &ArgMatches) { let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy"); @@ -380,7 +400,8 @@ pub fn run(clap_config: &ArgMatches) { .collect() }; - // generate some stats: + // generate some stats + let stats_formatted = gather_stats(&clippy_warnings); // grab crashes/ICEs, save the crate name and the ice message let ices: Vec<(&String, &String)> = clippy_warnings @@ -389,23 +410,6 @@ pub fn run(clap_config: &ArgMatches) { .map(|w| (&w.crate_name, &w.message)) .collect(); - // count lint type occurrences - let mut counter: HashMap<&String, usize> = HashMap::new(); - clippy_warnings - .iter() - .for_each(|wrn| *counter.entry(&wrn.linttype).or_insert(0) += 1); - - // collect into a tupled list for sorting - let mut stats: Vec<(&&String, &usize)> = counter.iter().map(|(lint, count)| (lint, count)).collect(); - // sort by "000{count} {clippy::lintname}" - // to not have a lint with 200 and 2 warnings take the same spot - stats.sort_by_key(|(lint, count)| format!("{:0>4}, {}", count, lint)); - - let stats_formatted: String = stats - .iter() - .map(|(lint, count)| format!("{} {}\n", lint, count)) - .collect::<String>(); - let mut all_msgs: Vec<String> = clippy_warnings.iter().map(|warning| warning.to_string()).collect(); all_msgs.sort(); all_msgs.push("\n\n\n\nStats\n\n".into()); |
