Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIIR update_lints: Update changelog links #3327

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
12 changes: 10 additions & 2 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a Vec because the iterator would have been consumed the first time it's used. Now it's cloning the Vec for every replace_region_in_file. Not sure if there's a better way. At least the files are only parsed once.

let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
let lint_count = usable_lints.len();

replace_region_in_file(
Expand All @@ -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()) }
);
}