Skip to content

Commit f1cbf6e

Browse files
authored
Merge pull request #12 from golemcloud/lib-improvements-3
Lib improvements 3
2 parents b1f5f0f + 504c8e0 commit f1cbf6e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub fn gen(
6767
name: &str,
6868
version: &str,
6969
overwrite_cargo: bool,
70+
disable_clippy: bool,
7071
) -> Result<()> {
7172
let open_api = merge_all_openapi_specs(openapi_specs)?;
7273

@@ -125,13 +126,13 @@ pub fn gen(
125126

126127
std::fs::write(
127128
src.join("api.rs"),
128-
rust::lib_gen::lib_gen("crate::api", &api_module_defs),
129+
rust::lib_gen::lib_gen("crate::api", &api_module_defs, disable_clippy),
129130
)
130131
.unwrap();
131132

132133
std::fs::write(
133134
src.join("model.rs"),
134-
rust::lib_gen::lib_gen("crate::model", &models),
135+
rust::lib_gen::lib_gen("crate::model", &models, disable_clippy),
135136
)
136137
.unwrap();
137138

@@ -145,7 +146,7 @@ pub fn gen(
145146
errors.def,
146147
];
147148

148-
let lib = rust::lib_gen::lib_gen("crate", &module_defs);
149+
let lib = rust::lib_gen::lib_gen("crate", &module_defs, disable_clippy);
149150
std::fs::write(src.join("lib.rs"), lib).unwrap();
150151

151152
if overwrite_cargo {

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn main() {
6363
&args.name,
6464
&args.client_version,
6565
true,
66+
false,
6667
)
6768
.unwrap();
6869
}

src/rust/lib_gen.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl ModuleDef {
9292
}
9393
}
9494

95-
pub fn lib_gen(self_name: &str, modules: &[ModuleDef]) -> String {
95+
pub fn lib_gen(self_name: &str, modules: &[ModuleDef], disable_clippy: bool) -> String {
9696
let mods = modules
9797
.iter()
9898
.map(|m| &m.name)
@@ -108,7 +108,12 @@ pub fn lib_gen(self_name: &str, modules: &[ModuleDef]) -> String {
108108
.reduce(|acc, e| acc + e)
109109
.unwrap_or_else(unit);
110110

111-
let code = line(unit() + "#![allow(clippy::all)]") + NewLine + mods + NewLine + uses;
111+
let base = if disable_clippy {
112+
line(unit() + "#[allow(clippy::all)]")
113+
} else {
114+
unit()
115+
};
116+
let code = base + NewLine + mods + NewLine + uses;
112117

113118
RustContext::new().print_to_string(code)
114119
}
@@ -133,10 +138,11 @@ mod tests {
133138
exports: vec!["A".to_string(), "Y".to_string()],
134139
},
135140
],
141+
true,
136142
);
137143

138144
let expected = indoc! { r#"
139-
#![allow(clippy::all)]
145+
#[allow(clippy::all)]
140146
141147
mod abc;
142148
mod xyz;

0 commit comments

Comments
 (0)