Skip to content

Commit 9f3ac4e

Browse files
committed
RIIR update_lints: Update changelog links
This now also updates the link list at the bottom of the changelog.
1 parent 284c63e commit 9f3ac4e

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

clippy_dev/src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,29 @@ impl Lint {
5959

6060
/// Returns all non-deprecated lints and non-internal lints
6161
pub fn usable_lints(lints: impl Iterator<Item=Self>) -> impl Iterator<Item=Self> {
62-
lints.filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal"))
62+
lints.filter(|l| l.deprecation.is_none() && !l.is_internal())
6363
}
6464

6565
/// Returns the lints in a HashMap, grouped by the different lint groups
6666
pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> {
6767
lints.iter().map(|lint| (lint.group.to_string(), lint.clone())).into_group_map()
6868
}
69+
70+
pub fn is_internal(&self) -> bool {
71+
self.group.starts_with("internal")
72+
}
73+
}
74+
75+
pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
76+
let mut lint_list_sorted: Vec<Lint> = lints;
77+
lint_list_sorted.sort_by_key(|l| l.name.clone());
78+
lint_list_sorted
79+
.iter()
80+
.filter(|l| !l.is_internal())
81+
.map(|l| {
82+
format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name)
83+
})
84+
.collect()
6985
}
7086

7187
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
@@ -291,3 +307,17 @@ fn test_by_lint_group() {
291307
]);
292308
assert_eq!(expected, Lint::by_lint_group(&lints));
293309
}
310+
311+
#[test]
312+
fn test_gen_changelog_lint_list() {
313+
let lints = vec![
314+
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
315+
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
316+
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
317+
];
318+
let expected = vec![
319+
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
320+
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string())
321+
];
322+
assert_eq!(expected, gen_changelog_lint_list(lints));
323+
}

clippy_dev/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ fn print_lints() {
5959
}
6060

6161
fn update_lints() {
62-
let lint_list = gather_all();
63-
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
62+
let lint_list: Vec<Lint> = gather_all().collect();
63+
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
6464
let lint_count = usable_lints.len();
6565

6666
replace_region_in_file(
@@ -74,4 +74,12 @@ fn update_lints() {
7474
]
7575
}
7676
);
77+
78+
replace_region_in_file(
79+
"../CHANGELOG.md",
80+
"<!-- begin autogenerated links to lint list -->",
81+
"<!-- end autogenerated links to lint list -->",
82+
false,
83+
|| { gen_changelog_lint_list(lint_list.clone()) }
84+
);
7785
}

0 commit comments

Comments
 (0)