diff --git a/clippy_dev/Cargo.lock b/clippy_dev/Cargo.lock index 8731a7c86..2d94755ba 100644 --- a/clippy_dev/Cargo.lock +++ b/clippy_dev/Cargo.lock @@ -48,10 +48,24 @@ name = "clippy_dev" version = "0.0.1" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "either" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "itertools" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lazy_static" version = "1.1.0" @@ -187,6 +201,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" +"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3b4142ab8738a78c51896f704f83c11df047ff1bda9a92a661aa6361552d93d" diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index 010380907..503dd53aa 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -5,5 +5,6 @@ authors = ["Philipp Hansch "] [dependencies] clap = "~2.32" +itertools = "0.7" regex = "1" lazy_static = "1.0" diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index e1de1bec5..8eabf3a97 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,8 +1,11 @@ extern crate regex; #[macro_use] extern crate lazy_static; +extern crate itertools; use regex::Regex; +use itertools::Itertools; +use std::collections::HashMap; use std::ffi::OsStr; use std::fs; use std::io::prelude::*; @@ -47,8 +50,9 @@ impl Lint { lints.iter().filter(|l| l.deprecation.is_none()).cloned().collect::>() } - pub fn in_lint_group(group: &str, lints: &[Lint]) -> Vec { - lints.iter().filter(|l| l.group == group).cloned().collect::>() + /// Returns the lints in a HashMap, grouped by the different lint groups + pub fn by_lint_group(lints: &[Lint]) -> HashMap> { + lints.iter().map(|lint| (lint.group.to_string(), lint.clone())).into_group_map() } } @@ -141,13 +145,19 @@ fn test_active_lints() { } #[test] -fn test_in_lint_group() { +fn test_by_lint_group() { let lints = vec![ - Lint::new("ptr_arg", "style", "really long text", None, "module_name"), - Lint::new("doc_markdown", "pedantic", "single line", None, "module_name"), + Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), + Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"), + Lint::new("incorrect_match", "group1", "abc", None, "module_name"), ]; - let expected = vec![ - Lint::new("ptr_arg", "style", "really long text", None, "module_name") - ]; - assert_eq!(expected, Lint::in_lint_group("style", &lints)); + let mut expected: HashMap> = HashMap::new(); + expected.insert("group1".to_string(), vec![ + Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), + Lint::new("incorrect_match", "group1", "abc", None, "module_name"), + ]); + expected.insert("group2".to_string(), vec![ + Lint::new("should_assert_eq2", "group2", "abc", None, "module_name") + ]); + assert_eq!(expected, Lint::by_lint_group(&lints)); } diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 7bf6eb012..6b55a7b7b 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -28,26 +28,18 @@ fn main() { fn print_lints() { let lint_list = collect_all(); - let print_clippy_lint_groups: [&str; 7] = [ - "correctness", - "style", - "complexity", - "perf", - "pedantic", - "nursery", - "restriction" - ]; - // We could use itertools' group_by to make this much more concise: - for group in &print_clippy_lint_groups { - println!("\n## {}", group); + let grouped_by_lint_group = Lint::by_lint_group(&lint_list); - let mut group_lints = Lint::in_lint_group(group, &lint_list); - group_lints.sort_by(|a, b| a.name.cmp(&b.name)); + for (lint_group, mut lints) in grouped_by_lint_group { + if lint_group == "Deprecated" { continue; } + println!("\n## {}", lint_group); - for lint in group_lints { - if lint.deprecation.is_some() { continue; } + lints.sort_by(|a, b| a.name.cmp(&b.name)); + + for lint in lints { println!("* [{}]({}#{}) ({})", lint.name, clippy_dev::DOCS_LINK.clone(), lint.name, lint.desc); } } + println!("there are {} lints", Lint::active_lints(&lint_list).len()); }