improved whitespace handling (#6)

This commit is contained in:
Adam Leventhal 2021-10-03 21:14:01 -07:00 committed by GitHub
parent 874f959a75
commit 7e16140b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

1
Cargo.lock generated
View File

@ -175,6 +175,7 @@ dependencies = [
"openapiv3",
"proc-macro2",
"quote",
"regex",
"rustfmt-wrapper",
"schemars",
"serde",

View File

@ -13,6 +13,7 @@ indexmap = "1.7.0"
openapiv3 = "1.0.0-beta.2"
proc-macro2 = "1.0.29"
quote = "1.0.9"
regex = "1.5.4"
rustfmt-wrapper = { git = "https://github.com/oxidecomputer/typify" }
schemars = "0.8.5"
serde = { version = "1", features = [ "derive" ] }

View File

@ -824,10 +824,10 @@ fn generate(api: &OpenAPI, ts: &mut TypeSpace) -> Result<String> {
#(#methods)*
}
};
let file = rustfmt_wrapper::rustfmt(file)
.unwrap()
// Format any indented item.
.replace(" }\n", " }\n\n");
let regex = regex::Regex::new(r#"(})(\n\s*[^} ])"#).unwrap();
let file = rustfmt_wrapper::rustfmt(file).unwrap();
let file = regex.replace_all(&file, "$1\n$2").to_string();
Ok(file)
}