mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Build lint lists once and the reuse them to update files
This commit is contained in:
parent
da679825e0
commit
98c30fea8c
2 changed files with 42 additions and 39 deletions
|
@ -62,13 +62,25 @@ 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"))
|
||||
#[must_use]
|
||||
pub fn usable_lints(lints: &[Self]) -> Vec<Self> {
|
||||
lints
|
||||
.iter()
|
||||
.filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal"))
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns all internal lints (not `internal_warn` lints)
|
||||
pub fn internal_lints(lints: impl Iterator<Item = Self>) -> impl Iterator<Item = Self> {
|
||||
lints.filter(|l| l.group == "internal")
|
||||
#[must_use]
|
||||
pub fn internal_lints(lints: &[Self]) -> Vec<Self> {
|
||||
lints.iter().filter(|l| l.group == "internal").cloned().collect()
|
||||
}
|
||||
|
||||
/// Returns all deprecated lints
|
||||
#[must_use]
|
||||
pub fn deprecated_lints(lints: &[Self]) -> Vec<Self> {
|
||||
lints.iter().filter(|l| l.deprecation.is_some()).cloned().collect()
|
||||
}
|
||||
|
||||
/// Returns the lints in a `HashMap`, grouped by the different lint groups
|
||||
|
@ -80,9 +92,8 @@ impl Lint {
|
|||
|
||||
/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
|
||||
#[must_use]
|
||||
pub fn gen_lint_group_list(lints: &[Lint]) -> Vec<String> {
|
||||
pub fn gen_lint_group_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
|
||||
lints
|
||||
.into_iter()
|
||||
.filter_map(|l| {
|
||||
if l.deprecation.is_some() {
|
||||
None
|
||||
|
@ -96,9 +107,8 @@ pub fn gen_lint_group_list(lints: &[Lint]) -> Vec<String> {
|
|||
|
||||
/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
|
||||
#[must_use]
|
||||
pub fn gen_modules_list(lints: &[Lint]) -> Vec<String> {
|
||||
pub fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
|
||||
lints
|
||||
.iter()
|
||||
.map(|l| &l.module)
|
||||
.unique()
|
||||
.map(|module| format!("pub mod {};", module))
|
||||
|
@ -108,9 +118,8 @@ pub fn gen_modules_list(lints: &[Lint]) -> Vec<String> {
|
|||
|
||||
/// Generates the list of lint links at the bottom of the README
|
||||
#[must_use]
|
||||
pub fn gen_changelog_lint_list(lints: &[Lint]) -> Vec<String> {
|
||||
pub fn gen_changelog_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
|
||||
lints
|
||||
.iter()
|
||||
.sorted_by_key(|l| l.name.clone())
|
||||
.filter_map(|l| {
|
||||
if l.group.starts_with("internal") {
|
||||
|
@ -124,9 +133,8 @@ pub fn gen_changelog_lint_list(lints: &[Lint]) -> Vec<String> {
|
|||
|
||||
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
|
||||
#[must_use]
|
||||
pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
|
||||
pub fn gen_deprecated<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
|
||||
lints
|
||||
.iter()
|
||||
.filter_map(|l| {
|
||||
l.clone().deprecation.map(|depr_text| {
|
||||
vec![
|
||||
|
@ -142,11 +150,10 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn gen_register_lint_list(lints: &[Lint]) -> Vec<String> {
|
||||
pub fn gen_register_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
|
||||
let pre = " store.register_lints(&[".to_string();
|
||||
let post = " ]);".to_string();
|
||||
let mut inner = lints
|
||||
.iter()
|
||||
.map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
|
||||
.sorted()
|
||||
.collect::<Vec<String>>();
|
||||
|
@ -421,7 +428,7 @@ fn test_usable_lints() {
|
|||
None,
|
||||
"module_name",
|
||||
)];
|
||||
assert_eq!(expected, Lint::usable_lints(lints.into_iter()).collect::<Vec<Lint>>());
|
||||
assert_eq!(expected, Lint::usable_lints(&lints));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -457,7 +464,7 @@ fn test_gen_changelog_lint_list() {
|
|||
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));
|
||||
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -492,7 +499,7 @@ fn test_gen_deprecated() {
|
|||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
assert_eq!(expected, gen_deprecated(&lints));
|
||||
assert_eq!(expected, gen_deprecated(lints.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -507,7 +514,7 @@ fn test_gen_modules_list() {
|
|||
"pub mod another_module;".to_string(),
|
||||
"pub mod module_name;".to_string(),
|
||||
];
|
||||
assert_eq!(expected, gen_modules_list(&lints));
|
||||
assert_eq!(expected, gen_modules_list(lints.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -523,5 +530,5 @@ fn test_gen_lint_group_list() {
|
|||
" LintId::of(&module_name::INTERNAL),".to_string(),
|
||||
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
|
||||
];
|
||||
assert_eq!(expected, gen_lint_group_list(&lints));
|
||||
assert_eq!(expected, gen_lint_group_list(lints.iter()));
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ pub enum UpdateMode {
|
|||
pub fn run(update_mode: UpdateMode) {
|
||||
let lint_list: Vec<Lint> = gather_all().collect();
|
||||
|
||||
let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
|
||||
|
||||
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
|
||||
let usable_lint_count = round_to_fifty(usable_lints.len());
|
||||
|
||||
let internal_lints = Lint::internal_lints(&lint_list);
|
||||
let deprecated_lints = Lint::deprecated_lints(&lint_list);
|
||||
let usable_lints = Lint::usable_lints(&lint_list);
|
||||
let mut sorted_usable_lints = usable_lints.clone();
|
||||
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
|
||||
|
||||
let usable_lint_count = round_to_fifty(usable_lints.len());
|
||||
|
||||
let mut file_change = replace_region_in_file(
|
||||
Path::new("src/lintlist/mod.rs"),
|
||||
"begin lint list",
|
||||
|
@ -61,7 +61,7 @@ pub fn run(update_mode: UpdateMode) {
|
|||
"<!-- end autogenerated links to lint list -->",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_changelog_lint_list(&lint_list),
|
||||
|| gen_changelog_lint_list(usable_lints.iter().chain(deprecated_lints.iter())),
|
||||
)
|
||||
.changed;
|
||||
|
||||
|
@ -71,7 +71,7 @@ pub fn run(update_mode: UpdateMode) {
|
|||
"end deprecated lints",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_deprecated(&lint_list),
|
||||
|| gen_deprecated(deprecated_lints.iter()),
|
||||
)
|
||||
.changed;
|
||||
|
||||
|
@ -81,7 +81,7 @@ pub fn run(update_mode: UpdateMode) {
|
|||
"end register lints",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_register_lint_list(&usable_lints),
|
||||
|| gen_register_lint_list(usable_lints.iter().chain(internal_lints.iter())),
|
||||
)
|
||||
.changed;
|
||||
|
||||
|
@ -91,7 +91,7 @@ pub fn run(update_mode: UpdateMode) {
|
|||
"end lints modules",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_modules_list(&usable_lints),
|
||||
|| gen_modules_list(usable_lints.iter()),
|
||||
)
|
||||
.changed;
|
||||
|
||||
|
@ -104,15 +104,11 @@ pub fn run(update_mode: UpdateMode) {
|
|||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
// clippy::all should only include the following lint groups:
|
||||
let all_group_lints = usable_lints
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter(|l| {
|
||||
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let all_group_lints = usable_lints.iter().filter(|l| {
|
||||
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
|
||||
});
|
||||
|
||||
gen_lint_group_list(&all_group_lints)
|
||||
gen_lint_group_list(all_group_lints)
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
@ -125,7 +121,7 @@ pub fn run(update_mode: UpdateMode) {
|
|||
r#"\]\);"#,
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_lint_group_list(&lints),
|
||||
|| gen_lint_group_list(lints.iter()),
|
||||
)
|
||||
.changed;
|
||||
}
|
||||
|
@ -140,8 +136,8 @@ pub fn run(update_mode: UpdateMode) {
|
|||
}
|
||||
|
||||
pub fn print_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();
|
||||
let usable_lints = Lint::usable_lints(&lint_list);
|
||||
let usable_lint_count = usable_lints.len();
|
||||
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
|
||||
|
||||
|
|
Loading…
Reference in a new issue