Skip to content

Commit

Permalink
Disable clippy on generated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Mar 20, 2024
1 parent c6d8d2e commit 7894809
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/rust/lib_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,51 @@ impl Verbosity {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub enum Attribute {
DenyClippy,
}

impl Attribute {
fn code(&self) -> RustPrinter {
match self {
Attribute::DenyClippy => line(unit() + "#![deny(clippy)]"),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct ModuleName {
name: String,
verbosity: Verbosity,
attributes: Vec<Attribute>,
}

impl ModuleName {
fn code(&self) -> RustPrinter {
line(unit() + self.verbosity.render() + "mod " + escape_keywords(&self.name) + ";")
unit()
+ self
.attributes
.iter()
.map(|a| a.code())
.reduce(|acc, e| acc + line(e))
.unwrap_or_else(unit)
+ line(unit() + self.verbosity.render() + "mod " + escape_keywords(&self.name) + ";")
}

pub fn new<S: Into<String>>(s: S) -> ModuleName {
ModuleName {
name: s.into(),
verbosity: Verbosity::Default,
attributes: vec![Attribute::DenyClippy],
}
}

pub fn new_pub<S: Into<String>>(s: S) -> ModuleName {
ModuleName {
name: s.into(),
verbosity: Verbosity::Pub,
attributes: vec![Attribute::DenyClippy],
}
}

Expand Down Expand Up @@ -136,7 +159,9 @@ mod tests {
);

let expected = indoc! { r#"
#![deny(clippy)]
mod abc;
#![deny(clippy)]
mod xyz;
pub use lib::abc::B;
Expand Down

0 comments on commit 7894809

Please sign in to comment.