Skip to content

Commit 913caa1

Browse files
committed
cargo dev crater: gather and save lint statistics (how often a lint triggered)
1 parent 9149002 commit 913caa1

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

clippy_dev/src/crater.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,30 @@ pub fn run() {
224224
.flatten()
225225
.collect();
226226

227-
let all_msgs: Vec<String> = clippy_warnings.iter().map(|warning| warning.to_string()).collect();
227+
// generate some stats:
228+
229+
// count lint type occurrences
230+
let mut counter: HashMap<&String, usize> = HashMap::new();
231+
clippy_warnings
232+
.iter()
233+
.for_each(|wrn| *counter.entry(&wrn.linttype).or_insert(0) += 1);
234+
235+
// collect into a tupled list for sorting
236+
let mut stats: Vec<(&&String, &usize)> = counter.iter().map(|(lint, count)| (lint, count)).collect();
237+
// sort by number of lint occurences
238+
stats.sort_by_key(|(_, count)| *count);
239+
// biggest number first
240+
stats.reverse();
241+
242+
let stats_formatted: String = stats
243+
.iter()
244+
.map(|(lint, count)| format!("{} {}\n", lint, count))
245+
.collect::<String>();
246+
247+
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(|warning| warning.to_string()).collect();
248+
all_msgs.sort();
249+
all_msgs.push("\n\n\n\nStats\n\n".into());
250+
all_msgs.push(stats_formatted);
228251

229252
// save the text into mini-crater/logs.txt
230253
let text = all_msgs.join("");

mini-crater/logs.txt

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,3 +3247,115 @@ xsv/0.13.0/src/select.rs:99:17 clippy::similar_names "binding's name is too simi
32473247
xsv/0.13.0/src/util.rs:150:5 clippy::doc_markdown "you should put bare URLs between `<`/`>` or make a proper Markdown link"
32483248
xsv/0.13.0/src/util.rs:37:33 clippy::map_clone "you are using an explicit closure for copying elements"
32493249
xsv/0.13.0/src/util.rs:90:1 clippy::needless_lifetimes "explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)"
3250+
3251+
3252+
3253+
3254+
Stats
3255+
3256+
clippy::must_use_candidate 552
3257+
clippy::unreadable_literal 365
3258+
clippy::missing_errors_doc 338
3259+
clippy::doc_markdown 178
3260+
clippy::wildcard_imports 160
3261+
clippy::items_after_statements 139
3262+
clippy::module_name_repetitions 137
3263+
clippy::redundant_closure_for_method_calls 135
3264+
clippy::redundant_field_names 111
3265+
clippy::cast_possible_truncation 91
3266+
clippy::similar_names 79
3267+
clippy::match_same_arms 64
3268+
clippy::inline_always 59
3269+
clippy::single_match_else 45
3270+
clippy::unseparated_literal_suffix 41
3271+
clippy::enum_glob_use 40
3272+
clippy::cast_precision_loss 35
3273+
clippy::if_not_else 35
3274+
clippy::filter_map 31
3275+
clippy::too_many_lines 31
3276+
clippy::redundant_else 29
3277+
clippy::trivially_copy_pass_by_ref 26
3278+
clippy::cast_lossless 23
3279+
clippy::redundant_static_lifetimes 21
3280+
clippy::struct_excessive_bools 20
3281+
clippy::map_unwrap_or 20
3282+
clippy::unusual_byte_groupings 19
3283+
clippy::unused_self 19
3284+
clippy::cast_possible_wrap 19
3285+
clippy::cast_sign_loss 19
3286+
clippy::unnecessary_wraps 19
3287+
clippy::needless_pass_by_value 18
3288+
clippy::default_trait_access 16
3289+
clippy::linkedlist 14
3290+
clippy::single_char_add_str 14
3291+
clippy::shadow_unrelated 13
3292+
clippy::cargo_common_metadata 13
3293+
clippy::option_if_let_else 12
3294+
clippy::needless_lifetimes 12
3295+
clippy::multiple_crate_versions 11
3296+
clippy::needless_doctest_main 10
3297+
clippy::missing_safety_doc 10
3298+
clippy::manual_range_contains 10
3299+
clippy::match_wildcard_for_single_variants 10
3300+
clippy::find_map 9
3301+
clippy::wrong_self_convention 8
3302+
clippy::invalid_upcast_comparisons 8
3303+
clippy::option_map_unit_fn 7
3304+
clippy::map_clone 7
3305+
clippy::explicit_into_iter_loop 7
3306+
clippy::range_plus_one 7
3307+
clippy::manual_strip 6
3308+
clippy::non_ascii_literal 6
3309+
clippy::single_component_path_imports 6
3310+
clippy::field_reassign_with_default 5
3311+
clippy::new_without_default 5
3312+
clippy::len_without_is_empty 5
3313+
clippy::identity_op 5
3314+
clippy::needless_return 5
3315+
clippy::empty_enum 5
3316+
clippy::match_like_matches_macro 5
3317+
clippy::explicit_iter_loop 5
3318+
clippy::too_many_arguments 4
3319+
clippy::let_underscore_drop 4
3320+
clippy::if_same_then_else 4
3321+
clippy::filter_map_next 3
3322+
clippy::zero_ptr 3
3323+
clippy::fn_params_excessive_bools 3
3324+
clippy::mut_mut 3
3325+
clippy::manual_non_exhaustive 2
3326+
clippy::comparison_to_empty 2
3327+
clippy::question_mark 2
3328+
clippy::redundant_pattern_matching 2
3329+
clippy::write_with_newline 2
3330+
clippy::unnecessary_cast 2
3331+
clippy::option_option 2
3332+
clippy::match_on_vec_items 2
3333+
clippy::type_complexity 2
3334+
clippy::len_zero 2
3335+
clippy::expl_impl_clone_on_copy 2
3336+
clippy::option_as_ref_deref 2
3337+
clippy::unused_unit 2
3338+
clippy::derive_hash_xor_eq 2
3339+
clippy::while_let_on_iterator 1
3340+
clippy::clone_on_copy 1
3341+
clippy::same_item_push 1
3342+
clippy::from_iter_instead_of_collect 1
3343+
clippy::or_fun_call 1
3344+
clippy::pub_enum_variant_names 1
3345+
clippy::used_underscore_binding 1
3346+
clippy::precedence 1
3347+
clippy::redundant_clone 1
3348+
clippy::collapsible_if 1
3349+
clippy::stable_sort_primitive 1
3350+
clippy::unit_arg 1
3351+
clippy::nonminimal_bool 1
3352+
clippy::comparison_chain 1
3353+
clippy::mem_replace_with_default 1
3354+
clippy::manual_saturating_arithmetic 1
3355+
clippy::expect_fun_call 1
3356+
clippy::should_implement_trait 1
3357+
clippy::verbose_bit_mask 1
3358+
clippy::int_plus_one 1
3359+
clippy::unnecessary_lazy_evaluations 1
3360+
clippy::from_over_into 1
3361+
clippy::explicit_deref_methods 1

0 commit comments

Comments
 (0)