about summary refs log tree commit diff
path: root/clippy_dev/src
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2018-11-03 12:59:13 +0100
committerPhilipp Hansch <dev@phansch.net>2018-11-03 13:43:35 +0100
commit4f38538d7585caed83bb6a95ede130f407ca7d3f (patch)
tree128e2ebb0cd5e247d030979b8c37b1279302134b /clippy_dev/src
parent6e3320c7efc9cdaa1ddb3865181ec017d9f5de26 (diff)
downloadrust-4f38538d7585caed83bb6a95ede130f407ca7d3f.tar.gz
rust-4f38538d7585caed83bb6a95ede130f407ca7d3f.zip
RIIR update lints: Generate lint group registrations
Diffstat (limited to 'clippy_dev/src')
-rw-r--r--clippy_dev/src/lib.rs28
-rw-r--r--clippy_dev/src/main.rs30
2 files changed, 58 insertions, 0 deletions
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index 28cc4600a09..f16ea14a3de 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -72,6 +72,19 @@ impl Lint {
     }
 }
 
+/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
+pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
+    lints.into_iter()
+        .filter_map(|l| {
+            if l.is_internal() || l.deprecation.is_some() {
+                None
+            } else {
+                Some(format!("        {}::{},", l.module, l.name.to_uppercase()))
+            }
+        })
+        .sorted()
+}
+
 /// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
 pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> {
     lints.into_iter()
@@ -390,3 +403,18 @@ fn test_gen_modules_list() {
     ];
     assert_eq!(expected, gen_modules_list(lints));
 }
+
+#[test]
+fn test_gen_lint_group_list() {
+    let lints = vec![
+        Lint::new("abc", "group1", "abc", None, "module_name"),
+        Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
+        Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
+        Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
+    ];
+    let expected = vec![
+        "        module_name::ABC,".to_string(),
+        "        module_name::SHOULD_ASSERT_EQ,".to_string(),
+    ];
+    assert_eq!(expected, gen_lint_group_list(lints));
+}
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index 4832b428e9c..128feaa8aea 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -98,4 +98,34 @@ fn update_lints() {
         false,
         || { gen_modules_list(lint_list.clone()) }
     );
+
+    // Generate lists of lints in the clippy::all lint group
+    replace_region_in_file(
+        "../clippy_lints/src/lib.rs",
+        r#"reg.register_lint_group\("clippy::all""#,
+        r#"\]\);"#,
+        false,
+        || {
+            // clippy::all should only include the following lint groups:
+            let all_group_lints = usable_lints.clone().into_iter().filter(|l| {
+                l.group == "correctness" ||
+                  l.group == "style" ||
+                  l.group == "complexity" ||
+                  l.group == "perf"
+            }).collect();
+
+            gen_lint_group_list(all_group_lints)
+        }
+    );
+
+    // Generate the list of lints for all other lint groups
+    for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
+        replace_region_in_file(
+            "../clippy_lints/src/lib.rs",
+            &format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
+            r#"\]\);"#,
+            false,
+            || { gen_lint_group_list(lints.clone()) }
+        );
+    }
 }