RIIR update lints: Generate lint group registrations

This commit is contained in:
Philipp Hansch
2018-11-03 12:59:13 +01:00
parent 6e3320c7ef
commit 4f38538d75
2 changed files with 58 additions and 0 deletions

View File

@@ -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));
}