Skip to content

Commit 4f38538

Browse files
committed
RIIR update lints: Generate lint group registrations
1 parent 6e3320c commit 4f38538

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

clippy_dev/src/lib.rs

+28
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ impl Lint {
7272
}
7373
}
7474

75+
/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
76+
pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
77+
lints.into_iter()
78+
.filter_map(|l| {
79+
if l.is_internal() || l.deprecation.is_some() {
80+
None
81+
} else {
82+
Some(format!(" {}::{},", l.module, l.name.to_uppercase()))
83+
}
84+
})
85+
.sorted()
86+
}
87+
7588
/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
7689
pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> {
7790
lints.into_iter()
@@ -390,3 +403,18 @@ fn test_gen_modules_list() {
390403
];
391404
assert_eq!(expected, gen_modules_list(lints));
392405
}
406+
407+
#[test]
408+
fn test_gen_lint_group_list() {
409+
let lints = vec![
410+
Lint::new("abc", "group1", "abc", None, "module_name"),
411+
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
412+
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
413+
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
414+
];
415+
let expected = vec![
416+
" module_name::ABC,".to_string(),
417+
" module_name::SHOULD_ASSERT_EQ,".to_string(),
418+
];
419+
assert_eq!(expected, gen_lint_group_list(lints));
420+
}

clippy_dev/src/main.rs

+30
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,34 @@ fn update_lints() {
9898
false,
9999
|| { gen_modules_list(lint_list.clone()) }
100100
);
101+
102+
// Generate lists of lints in the clippy::all lint group
103+
replace_region_in_file(
104+
"../clippy_lints/src/lib.rs",
105+
r#"reg.register_lint_group\("clippy::all""#,
106+
r#"\]\);"#,
107+
false,
108+
|| {
109+
// clippy::all should only include the following lint groups:
110+
let all_group_lints = usable_lints.clone().into_iter().filter(|l| {
111+
l.group == "correctness" ||
112+
l.group == "style" ||
113+
l.group == "complexity" ||
114+
l.group == "perf"
115+
}).collect();
116+
117+
gen_lint_group_list(all_group_lints)
118+
}
119+
);
120+
121+
// Generate the list of lints for all other lint groups
122+
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
123+
replace_region_in_file(
124+
"../clippy_lints/src/lib.rs",
125+
&format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
126+
r#"\]\);"#,
127+
false,
128+
|| { gen_lint_group_list(lints.clone()) }
129+
);
130+
}
101131
}

0 commit comments

Comments
 (0)