Skip to content

Commit 5e75d82

Browse files
authored
Cargo Fmt on Generated Rust Files (#79)
* Run cargo fmt on all rust output files * Lint fix --------- Co-authored-by: Boppy <[email protected]>
1 parent c15dbdd commit 5e75d82

File tree

1 file changed

+23
-1
lines changed
  • crates/cli/src/subcommands/generate

1 file changed

+23
-1
lines changed

crates/cli/src/subcommands/generate/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
44
use clap::Arg;
55
use clap::ArgAction::SetTrue;
66
use convert_case::{Case, Casing};
7+
use duct::cmd;
78
use spacetimedb_lib::sats::{AlgebraicType, Typespace};
89
use spacetimedb_lib::{bsatn, MiscModuleExport, ModuleDef, ReducerDef, TableDef, TypeAlias};
910
use wasmtime::{AsContext, Caller, ExternType};
@@ -110,10 +111,15 @@ Failed to compile module {:?}. See cargo errors above for more details.",
110111
));
111112
}
112113

114+
let mut paths = vec![];
113115
for (fname, code) in generate(&wasm_file, lang, namespace.as_str())?.into_iter() {
114-
fs::write(out_dir.join(fname), code)?;
116+
let path = out_dir.join(fname);
117+
paths.push(path.clone());
118+
fs::write(path, code)?;
115119
}
116120

121+
format_files(paths, lang)?;
122+
117123
println!("Generate finished successfully.");
118124
Ok(())
119125
}
@@ -433,3 +439,19 @@ impl Memory {
433439
.get(..len as usize)
434440
}
435441
}
442+
443+
fn format_files(generated_files: Vec<PathBuf>, lang: Language) -> anyhow::Result<()> {
444+
match lang {
445+
Language::Rust => {
446+
cmd!("rustup", "component", "add", "rustfmt").run()?;
447+
for path in generated_files {
448+
cmd!("rustfmt", path.to_str().unwrap()).run()?;
449+
}
450+
}
451+
Language::Csharp => {}
452+
Language::TypeScript => {}
453+
Language::Python => {}
454+
}
455+
456+
Ok(())
457+
}

0 commit comments

Comments
 (0)