Use `prettyplease` to format the code

This commit is contained in:
Sunli 2022-08-09 14:46:59 +08:00
parent 4621a1c6c0
commit a54b131926
4 changed files with 2810 additions and 2139 deletions

View File

@ -19,4 +19,6 @@ serde_json = "1.0.64"
[dev-dependencies]
pest_generator = "2.1.3"
prettyplease = "0.1.18"
proc-macro2 = "1.0.37"
syn = "1.0.99"

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ use crate::{
mod executable;
#[allow(clippy::redundant_static_lifetimes)]
#[rustfmt::skip]
mod generated;
mod service;
mod utils;

View File

@ -3,11 +3,7 @@
//!
//! To avoid that, let's just dump generated code to string into this
//! repository, and add a test that checks that the code is fresh.
use std::{
fs,
io::Write,
process::{Command, Stdio},
};
use std::fs;
const PREAMBLE: &str = "\
//! This is @generated code, do not edit by hand.
@ -47,21 +43,8 @@ struct GraphQLParser;
}
fn reformat(code: &str) -> String {
let mut cmd = Command::new("rustfmt")
.args(&["--config", "tab_spaces=2"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
cmd.stdin
.take()
.unwrap()
.write_all(code.as_bytes())
.unwrap();
let output = cmd.wait_with_output().unwrap();
assert!(output.status.success());
String::from_utf8(output.stdout).unwrap()
let syntax_tree = syn::parse_str(code).unwrap();
prettyplease::unparse(&syntax_tree)
}
fn normalize(code: &str) -> String {