RIIR update lints: Generate deprecated lints

The update script now also generates the 'register_removed' section in
`clippy_lints/src/lib.rs`.

Also, instead of using `let mut store ...`, I added a new identifier
line so that the replacement will continue to work in case `let mut
store ...` ever changes.
This commit is contained in:
Philipp Hansch
2018-10-31 08:03:50 +01:00
parent e695015caa
commit 64bd658516
4 changed files with 43 additions and 1 deletions

View File

@@ -72,6 +72,7 @@ impl Lint {
}
}
/// Generates the list of lint links at the bottom of the README
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());
@@ -84,6 +85,23 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
.collect()
}
/// Generates the 'register_removed' code in `./clippy_lints/src/lib.rs`.
pub fn gen_deprecated(lints: Vec<Lint>) -> Vec<String> {
lints.iter()
.filter(|l| l.deprecation.is_some())
.map(|l| {
format!(
r#" store.register_removed(
"{}",
"{}",
);"#,
l.name,
l.deprecation.clone().unwrap()
)
})
.collect()
}
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
pub fn gather_all() -> impl Iterator<Item=Lint> {
lint_files().flat_map(|f| gather_from_file(&f))
@@ -321,3 +339,18 @@ fn test_gen_changelog_lint_list() {
];
assert_eq!(expected, gen_changelog_lint_list(lints));
}
#[test]
fn test_gen_deprecated() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "abc", Some("has been superseeded by should_assert_eq2"), "module_name"),
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")
];
let expected: Vec<String> = vec![
r#" store.register_removed(
"should_assert_eq",
"has been superseeded by should_assert_eq2",
);"#.to_string()
];
assert_eq!(expected, gen_deprecated(lints));
}