Use prettyplease
to format the code
This commit is contained in:
parent
4621a1c6c0
commit
a54b131926
|
@ -19,4 +19,6 @@ serde_json = "1.0.64"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pest_generator = "2.1.3"
|
pest_generator = "2.1.3"
|
||||||
|
prettyplease = "0.1.18"
|
||||||
proc-macro2 = "1.0.37"
|
proc-macro2 = "1.0.37"
|
||||||
|
syn = "1.0.99"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,7 @@ use crate::{
|
||||||
|
|
||||||
mod executable;
|
mod executable;
|
||||||
#[allow(clippy::redundant_static_lifetimes)]
|
#[allow(clippy::redundant_static_lifetimes)]
|
||||||
|
#[rustfmt::skip]
|
||||||
mod generated;
|
mod generated;
|
||||||
mod service;
|
mod service;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
//!
|
//!
|
||||||
//! To avoid that, let's just dump generated code to string into this
|
//! 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.
|
//! repository, and add a test that checks that the code is fresh.
|
||||||
use std::{
|
use std::fs;
|
||||||
fs,
|
|
||||||
io::Write,
|
|
||||||
process::{Command, Stdio},
|
|
||||||
};
|
|
||||||
|
|
||||||
const PREAMBLE: &str = "\
|
const PREAMBLE: &str = "\
|
||||||
//! This is @generated code, do not edit by hand.
|
//! This is @generated code, do not edit by hand.
|
||||||
|
@ -47,21 +43,8 @@ struct GraphQLParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reformat(code: &str) -> String {
|
fn reformat(code: &str) -> String {
|
||||||
let mut cmd = Command::new("rustfmt")
|
let syntax_tree = syn::parse_str(code).unwrap();
|
||||||
.args(&["--config", "tab_spaces=2"])
|
prettyplease::unparse(&syntax_tree)
|
||||||
.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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize(code: &str) -> String {
|
fn normalize(code: &str) -> String {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user