about summary refs log tree commit diff
path: root/clippy_dev/src
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2018-10-17 08:18:05 +0200
committerPhilipp Hansch <dev@phansch.net>2018-10-17 08:18:05 +0200
commit9f3ac4e5a396170c6f59e0f654c65b5ba0c4e5e5 (patch)
treeb66e353588b44c52ee3532afb37ca8525bf5296c /clippy_dev/src
parent284c63e84d21a844c0cbe6fc9d227f381f1b5130 (diff)
downloadrust-9f3ac4e5a396170c6f59e0f654c65b5ba0c4e5e5.tar.gz
rust-9f3ac4e5a396170c6f59e0f654c65b5ba0c4e5e5.zip
RIIR update_lints: Update changelog links
This now also updates the link list at the bottom of the changelog.
Diffstat (limited to 'clippy_dev/src')
-rw-r--r--clippy_dev/src/lib.rs32
-rw-r--r--clippy_dev/src/main.rs12
2 files changed, 41 insertions, 3 deletions
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index dcb2de2b1f8..77351233381 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -59,13 +59,29 @@ impl Lint {
 
     /// Returns all non-deprecated lints and non-internal lints
     pub fn usable_lints(lints: impl Iterator<Item=Self>) -> impl Iterator<Item=Self> {
-        lints.filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal"))
+        lints.filter(|l| l.deprecation.is_none() && !l.is_internal())
     }
 
     /// Returns the lints in a HashMap, grouped by the different lint groups
     pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> {
         lints.iter().map(|lint| (lint.group.to_string(), lint.clone())).into_group_map()
     }
+
+    pub fn is_internal(&self) -> bool {
+        self.group.starts_with("internal")
+    }
+}
+
+pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
+    let mut lint_list_sorted: Vec<Lint> = lints;
+    lint_list_sorted.sort_by_key(|l| l.name.clone());
+    lint_list_sorted
+        .iter()
+        .filter(|l| !l.is_internal())
+        .map(|l| {
+            format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name)
+        })
+        .collect()
 }
 
 /// Gathers all files in `src/clippy_lints` and gathers all lints inside
@@ -291,3 +307,17 @@ fn test_by_lint_group() {
     ]);
     assert_eq!(expected, Lint::by_lint_group(&lints));
 }
+
+#[test]
+fn test_gen_changelog_lint_list() {
+    let lints = vec![
+        Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
+        Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
+        Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
+    ];
+    let expected = vec![
+        format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
+        format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string())
+    ];
+    assert_eq!(expected, gen_changelog_lint_list(lints));
+}
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index 7b688836a95..8769ee6b810 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -59,8 +59,8 @@ fn print_lints() {
 }
 
 fn update_lints() {
-    let lint_list = gather_all();
-    let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
+    let lint_list: Vec<Lint> = gather_all().collect();
+    let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
     let lint_count = usable_lints.len();
 
     replace_region_in_file(
@@ -74,4 +74,12 @@ fn update_lints() {
             ]
         }
     );
+
+    replace_region_in_file(
+        "../CHANGELOG.md",
+        "<!-- begin autogenerated links to lint list -->",
+        "<!-- end autogenerated links to lint list -->",
+        false,
+        || { gen_changelog_lint_list(lint_list.clone()) }
+    );
 }