Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rex4539 committed Feb 3, 2025
1 parent 5f21b89 commit 1aea6da
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions eipw-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ enum Source<'a> {
File(&'a Path),
}

impl<'a> Source<'a> {
impl Source<'_> {
fn origin(&self) -> Option<&Path> {
match self {
Self::String {
Expand All @@ -509,8 +509,7 @@ impl<'a> Source<'a> {
Self::File(f) => fetch
.fetch(f.to_path_buf())
.await
.with_context(|_| IoSnafu { path: f.to_owned() })
.map_err(Into::into),
.with_context(|_| IoSnafu { path: f.to_owned() }),
Self::String { src, .. } => Ok((*src).to_owned()),
}
}
Expand Down Expand Up @@ -565,6 +564,10 @@ impl<M, L> Default for Options<M, L> {
}
}

// Type aliases for the iterators with lifetime annotations
type ModifierIterator<'a> = dyn Iterator<Item = Box<dyn Modifier>> + 'a;
type LintIterator<'a> = dyn Iterator<Item = (&'a str, Box<dyn Lint>)> + 'a;

impl<M, L, K> Options<Vec<M>, HashMap<K, L>>
where
M: 'static + Clone + Modifier,
Expand All @@ -574,17 +577,19 @@ where
pub fn to_iters(
&self,
) -> Options<
impl Iterator<Item = Box<dyn Modifier>> + '_,
impl Iterator<Item = (&'_ str, Box<dyn Lint>)>,
Box<ModifierIterator<'_>>, // Use boxed trait objects
Box<LintIterator<'_>>, // Use boxed trait objects
> {
let modifiers = self
.modifiers
.as_ref()
.map(|m| m.iter().map(|n| Box::new(n.clone()) as Box<dyn Modifier>));
let modifiers = self.modifiers.as_ref().map(|m| {
Box::new(m.iter().map(|n| Box::new(n.clone()) as Box<dyn Modifier>))
as Box<dyn Iterator<Item = Box<dyn Modifier>>>
});

let lints = self.lints.as_ref().map(|l| {
l.iter()
.map(|(k, v)| (k.as_ref(), Box::new(v.clone()) as Box<dyn Lint>))
Box::new(
l.iter()
.map(|(k, v)| (k.as_ref(), Box::new(v.clone()) as Box<dyn Lint>)),
) as Box<dyn Iterator<Item = (&'_ str, Box<dyn Lint>)>>
});

Options {
Expand Down Expand Up @@ -612,7 +617,7 @@ pub struct Linter<'a, R> {
fetch: Box<dyn fetch::Fetch>,
}

impl<'a, R> Default for Linter<'a, R>
impl<R> Default for Linter<'_, R>
where
R: Default,
{
Expand Down
2 changes: 1 addition & 1 deletion eipw-lint/src/lints/markdown/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct Visitor<'a, 'b, 'c> {
schema: Validator,
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
impl tree::Visitor for Visitor<'_, '_, '_> {
type Error = Error;

fn enter_code_block(&mut self, ast: &Ast, node: &NodeCodeBlock) -> Result<Next, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown/link_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Visitor<'a, 'b, 'c> {
own_number: Option<u32>,
}

impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
impl Visitor<'_, '_, '_> {
fn check(&self, ast: &Ast, text: &str) -> Result<Next, Error> {
for matched in self.re.captures_iter(text) {
let self_reference = match self.own_number {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
impl tree::Visitor for Visitor<'_, '_, '_> {
type Error = Error;

fn enter_front_matter(&mut self, _: &Ast, _: &str) -> Result<Next, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown/no_backticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Visitor<'a, 'b, 'c> {
slug: &'c str,
}

impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
impl Visitor<'_, '_, '_> {
fn check(&mut self, ast: &Ast, text: &str) -> Result<Next, Error> {
if !self.re.is_match(text) {
return Ok(Next::TraverseChildren);
Expand All @@ -74,7 +74,7 @@ impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
impl tree::Visitor for Visitor<'_, '_, '_> {
type Error = Error;

fn enter_code(&mut self, ast: &Ast, code: &NodeCode) -> Result<Next, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct ExcludesVisitor<'a, 'b, 'c> {
message: &'c str,
}

impl<'a, 'b, 'c> ExcludesVisitor<'a, 'b, 'c> {
impl ExcludesVisitor<'_, '_, '_> {
fn check(&self, ast: &Ast, buf: &str) -> Result<Next, Error> {
if !self.re.is_match(buf) {
return Ok(Next::TraverseChildren);
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'a, 'b, 'c> ExcludesVisitor<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> tree::Visitor for ExcludesVisitor<'a, 'b, 'c> {
impl tree::Visitor for ExcludesVisitor<'_, '_, '_> {
type Error = Error;

fn enter_front_matter(&mut self, _: &Ast, _: &str) -> Result<Next, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion eipw-lint/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ pub trait TraverseExt {
V: Visitor;
}

impl<'a> TraverseExt for Traverse<'a, RefCell<Ast>> {
impl TraverseExt for Traverse<'_, RefCell<Ast>> {
fn visit<V>(self, visitor: &mut V) -> Result<(), V::Error>
where
V: Visitor,
Expand Down

0 comments on commit 1aea6da

Please sign in to comment.