Skip to content

Commit 7894809

Browse files
committed
Disable clippy on generated modules
1 parent c6d8d2e commit 7894809

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/rust/lib_gen.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,51 @@ impl Verbosity {
3232
}
3333
}
3434

35+
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
36+
pub enum Attribute {
37+
DenyClippy,
38+
}
39+
40+
impl Attribute {
41+
fn code(&self) -> RustPrinter {
42+
match self {
43+
Attribute::DenyClippy => line(unit() + "#![deny(clippy)]"),
44+
}
45+
}
46+
}
47+
3548
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
3649
pub struct ModuleName {
3750
name: String,
3851
verbosity: Verbosity,
52+
attributes: Vec<Attribute>,
3953
}
4054

4155
impl ModuleName {
4256
fn code(&self) -> RustPrinter {
43-
line(unit() + self.verbosity.render() + "mod " + escape_keywords(&self.name) + ";")
57+
unit()
58+
+ self
59+
.attributes
60+
.iter()
61+
.map(|a| a.code())
62+
.reduce(|acc, e| acc + line(e))
63+
.unwrap_or_else(unit)
64+
+ line(unit() + self.verbosity.render() + "mod " + escape_keywords(&self.name) + ";")
4465
}
4566

4667
pub fn new<S: Into<String>>(s: S) -> ModuleName {
4768
ModuleName {
4869
name: s.into(),
4970
verbosity: Verbosity::Default,
71+
attributes: vec![Attribute::DenyClippy],
5072
}
5173
}
5274

5375
pub fn new_pub<S: Into<String>>(s: S) -> ModuleName {
5476
ModuleName {
5577
name: s.into(),
5678
verbosity: Verbosity::Pub,
79+
attributes: vec![Attribute::DenyClippy],
5780
}
5881
}
5982

@@ -136,7 +159,9 @@ mod tests {
136159
);
137160

138161
let expected = indoc! { r#"
162+
#![deny(clippy)]
139163
mod abc;
164+
#![deny(clippy)]
140165
mod xyz;
141166
142167
pub use lib::abc::B;

0 commit comments

Comments
 (0)