Build lint lists once and the reuse them to update files
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user