fix: use prettier-please just in tests - no custom wrapper (#2767)

* fix: use prettier-please just in tests - no custom wrapper
This commit is contained in:
Jonathan Kelley 2024-08-01 17:46:51 -07:00 committed by GitHub
parent e5e578d27b
commit ae4a2464b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 390 additions and 381 deletions

59
Cargo.lock generated
View file

@ -1326,9 +1326,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "bytes"
version = "1.7.0"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]]
name = "bzip2"
@ -5940,9 +5940,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]]
name = "liquid"
version = "0.26.8"
version = "0.26.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e9338405fdbc0bce9b01695b2a2ef6b20eca5363f385d47bce48ddf8323cc25"
checksum = "7cdcc72b82748f47c2933c172313f5a9aea5b2c4eb3fa4c66b4ea55bb60bb4b1"
dependencies = [
"doc-comment",
"liquid-core",
@ -5953,9 +5953,9 @@ dependencies = [
[[package]]
name = "liquid-core"
version = "0.26.8"
version = "0.26.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "feb8fed70857010ed9016ed2ce5a7f34e7cc51d5d7255c9c9dc2e3243e490b42"
checksum = "2752e978ffc53670f3f2e8b3ef09f348d6f7b5474a3be3f8a5befe5382e4effb"
dependencies = [
"anymap2",
"itertools 0.13.0",
@ -5971,9 +5971,9 @@ dependencies = [
[[package]]
name = "liquid-derive"
version = "0.26.7"
version = "0.26.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a5aa659a76b649f0d639ef0b9c067a9499c42a9d7f3e7832e279f791704966"
checksum = "3b51f1d220e3fa869e24cfd75915efe3164bd09bb11b3165db3f37f57bf673e3"
dependencies = [
"proc-macro2",
"quote",
@ -5982,9 +5982,9 @@ dependencies = [
[[package]]
name = "liquid-lib"
version = "0.26.8"
version = "0.26.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee1794b5605e9f8864a8a4f41aa97976b42512cc81093f8c885d29fb94c6c556"
checksum = "59b1a298d3d2287ee5b1e43840d885b8fdfc37d3f4e90d82aacfd04d021618da"
dependencies = [
"itertools 0.13.0",
"liquid-core",
@ -6826,12 +6826,12 @@ dependencies = [
[[package]]
name = "os_pipe"
version = "1.2.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29d73ba8daf8fac13b0501d1abeddcfe21ba7401ada61a819144b6c2a4f32209"
checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
dependencies = [
"libc",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@ -7428,9 +7428,9 @@ dependencies = [
[[package]]
name = "prettier-please"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22020dfcf177fcc7bf5deaf7440af371400c67c0de14c399938d8ed4fb4645d3"
checksum = "32db37eb2b0ec0af154e9c1b33425902d8cd9481e35167c4e9ffb28fec3916bb"
dependencies = [
"proc-macro2",
"syn 2.0.72",
@ -8647,9 +8647,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.121"
version = "1.0.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609"
checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da"
dependencies = [
"itoa 1.0.11",
"memchr",
@ -9638,9 +9638,9 @@ dependencies = [
[[package]]
name = "swc_common"
version = "0.36.2"
version = "0.36.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1802b1642488aec58597dc55ea88992c165660d6e44e9838d4d93f7b78ab95f3"
checksum = "457fb92efa9f0c849d6bc4e86561982d464176bc3df96bb22baed5e98309e090"
dependencies = [
"ahash 0.8.11",
"ast_node",
@ -10019,9 +10019,9 @@ dependencies = [
[[package]]
name = "swc_ecma_minifier"
version = "0.200.4"
version = "0.200.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b92feddb27f3ad89dd296696f55e04f8e96cdc778df95a73a6f06664bf6919f3"
checksum = "624e23b532c9a2f74ea850120b19079ab67f6e85af53c83d1984adbecc820b03"
dependencies = [
"arrayvec",
"indexmap 2.3.0",
@ -10054,9 +10054,9 @@ dependencies = [
[[package]]
name = "swc_ecma_parser"
version = "0.148.1"
version = "0.148.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8204235f635274dba4adc30c47ac896fd126ddfc53b27210676722423cbb2e7"
checksum = "a05ef8f80461e19374d9e8197f459a399b2802da19f72ea951ef343752ff3c04"
dependencies = [
"either",
"new_debug_unreachable",
@ -10302,9 +10302,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_typescript"
version = "0.194.3"
version = "0.194.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f73c4ae3eb15adc5865dc729c4e111040529cec5a349d56ed0b4a0de1a86242"
checksum = "99619353488c1dae960159faef86f0261e7fefe43b84ed1ba80c8cbc5a539434"
dependencies = [
"ryu-js",
"serde",
@ -12262,6 +12262,15 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-targets"
version = "0.42.2"

View file

@ -96,6 +96,10 @@ manganis-cli-support = { version = "0.3.0-alpha.0", features = ["html"] }
manganis = { version = "0.3.0-alpha.0", default-features = false }
warnings = { version = "0.2.0" }
# a fork of pretty please for tests
prettier-please = { version = "0.3.0", features = ["verbatim"]}
tracing = "0.1.37"
tracing-futures = "0.2.5"
toml = "0.8"

View file

@ -21,7 +21,6 @@ serde = { workspace = true, features = ["derive"], optional = true }
internment = { version = "0.7.0", optional = true }
tracing = { workspace = true }
proc-macro2-diagnostics = { version = "0.10", default-features = false }
prettier-please = { version = "*" }
[features]
default = ["hot_reload"]
@ -31,6 +30,7 @@ serde = ["dep:serde", "dioxus-core/serialize"]
[dev-dependencies]
prettyplease = { workspace = true }
prettier-please = { workspace = true }
[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]

View file

@ -341,9 +341,14 @@ fn normalize_path(name: &mut syn::Path) -> Option<AngleBracketedGenericArguments
generics
}
/// Ensure we can parse a component
#[test]
fn parses() {
#[cfg(test)]
mod tests {
use super::*;
use prettier_please::PrettyUnparse;
/// Ensure we can parse a component
#[test]
fn parses() {
let input = quote! {
MyComponent {
key: "value {something}",
@ -369,13 +374,13 @@ fn parses() {
let component: Component = syn::parse2(input_without_manual_props).unwrap();
dbg!(component);
}
}
/// Ensure we reject invalid forms
///
/// Maybe want to snapshot the errors?
#[test]
fn rejects() {
/// Ensure we reject invalid forms
///
/// Maybe want to snapshot the errors?
#[test]
fn rejects() {
let input = quote! {
myComponent {
key: "value",
@ -391,10 +396,10 @@ fn rejects() {
let component: Component = syn::parse2(input).unwrap();
dbg!(component.diagnostics);
}
}
#[test]
fn to_tokens_properly() {
#[test]
fn to_tokens_properly() {
let input = quote! {
MyComponent {
key: "value {something}",
@ -410,10 +415,10 @@ fn to_tokens_properly() {
let component: Component = syn::parse2(input).unwrap();
println!("{}", component.to_token_stream());
}
}
#[test]
fn to_tokens_no_manual_props() {
#[test]
fn to_tokens_no_manual_props() {
let input_without_manual_props = quote! {
MyComponent {
key: "value {something}",
@ -425,19 +430,19 @@ fn to_tokens_no_manual_props() {
};
let component: Component = syn::parse2(input_without_manual_props).unwrap();
println!("{}", component.to_token_stream().pretty_unparse());
}
}
#[test]
fn generics_params() {
#[test]
fn generics_params() {
let input_without_children = quote! {
Outlet::<R> {}
};
let component: crate::CallBody = syn::parse2(input_without_children).unwrap();
println!("{}", component.to_token_stream().pretty_unparse());
}
}
#[test]
fn generics_no_fish() {
#[test]
fn generics_no_fish() {
let name = quote! { Outlet<R> };
let mut p = syn::parse2::<syn::Path>(name).unwrap();
let generics = normalize_path(&mut p);
@ -450,10 +455,10 @@ fn generics_no_fish() {
};
let component: BodyNode = syn::parse2(input_without_children).unwrap();
println!("{}", component.to_token_stream().pretty_unparse());
}
}
#[test]
fn fmt_passes_properly() {
#[test]
fn fmt_passes_properly() {
let input = quote! {
Link { to: Route::List, class: "pure-button", "Go back" }
};
@ -461,10 +466,10 @@ fn fmt_passes_properly() {
let component: Component = syn::parse2(input).unwrap();
println!("{}", component.to_token_stream().pretty_unparse());
}
}
#[test]
fn incomplete_components() {
#[test]
fn incomplete_components() {
let input = quote::quote! {
some::cool::Component
};
@ -476,4 +481,5 @@ fn incomplete_components() {
};
let _parsed: syn::Path = syn::parse2(input).unwrap();
}
}

View file

@ -404,8 +404,13 @@ impl Display for ElementName {
}
}
#[test]
fn parses_name() {
#[cfg(test)]
mod tests {
use super::*;
use prettier_please::PrettyUnparse;
#[test]
fn parses_name() {
let _parsed: ElementName = syn::parse2(quote::quote! { div }).unwrap();
let _parsed: ElementName = syn::parse2(quote::quote! { some-cool-element }).unwrap();
@ -451,10 +456,10 @@ fn parses_name() {
.unwrap();
dbg!(parsed);
}
}
#[test]
fn parses_variety() {
#[test]
fn parses_variety() {
let input = quote::quote! {
div {
class: "hello world",
@ -477,10 +482,10 @@ fn parses_variety() {
let parsed: Element = syn::parse2(input).unwrap();
dbg!(parsed);
}
}
#[test]
fn to_tokens_properly() {
#[test]
fn to_tokens_properly() {
let input = quote::quote! {
div {
class: "hello world",
@ -502,10 +507,10 @@ fn to_tokens_properly() {
let parsed: Element = syn::parse2(input).unwrap();
println!("{}", parsed.to_token_stream().pretty_unparse());
}
}
#[test]
fn to_tokens_with_diagnostic() {
#[test]
fn to_tokens_with_diagnostic() {
let input = quote::quote! {
div {
class: "hello world",
@ -521,10 +526,10 @@ fn to_tokens_with_diagnostic() {
let parsed: Element = syn::parse2(input).unwrap();
println!("{}", parsed.to_token_stream().pretty_unparse());
}
}
#[test]
fn merges_attributes() {
#[test]
fn merges_attributes() {
let input = quote::quote! {
div {
class: "hello world",
@ -549,24 +554,24 @@ fn merges_attributes() {
AttributeValue::AttrLiteral(lit) => lit,
_ => panic!("expected literal"),
};
}
}
/// There are a number of cases where merging attributes doesn't make sense
/// - merging two expressions together
/// - merging two literals together
/// - merging a literal and an expression together
///
/// etc
///
/// We really only want to merge formatted things together
///
/// IE
/// class: "hello world ",
/// class: if some_expr { "abc" }
///
/// Some open questions - should the delimiter be explicit?
#[test]
fn merging_weird_fails() {
/// There are a number of cases where merging attributes doesn't make sense
/// - merging two expressions together
/// - merging two literals together
/// - merging a literal and an expression together
///
/// etc
///
/// We really only want to merge formatted things together
///
/// IE
/// class: "hello world ",
/// class: if some_expr { "abc" }
///
/// Some open questions - should the delimiter be explicit?
#[test]
fn merging_weird_fails() {
let input = quote::quote! {
div {
class: "hello world",
@ -593,10 +598,10 @@ fn merging_weird_fails() {
.diagnostics
.into_iter()
.any(|f| f.emit_as_item_tokens().to_string().contains("style")));
}
}
#[test]
fn diagnostics() {
#[test]
fn diagnostics() {
let input = quote::quote! {
p {
class: "foo bar"
@ -605,10 +610,10 @@ fn diagnostics() {
};
let _parsed: Element = syn::parse2(input).unwrap();
}
}
#[test]
fn parses_raw_elements() {
#[test]
fn parses_raw_elements() {
let input = quote::quote! {
use {
"hello"
@ -616,4 +621,5 @@ fn parses_raw_elements() {
};
let _parsed: Element = syn::parse2(input).unwrap();
}
}

View file

@ -34,7 +34,7 @@ impl ToTokens for ExprNode {
#[test]
fn no_commas() {
use crate::PrettyUnparse;
use prettier_please::PrettyUnparse;
let input = quote! {
div {
{label("Hello, world!")},

View file

@ -358,7 +358,7 @@ impl Parse for IfmtInput {
#[cfg(test)]
mod tests {
use super::*;
use crate::PrettyUnparse;
use prettier_please::PrettyUnparse;
#[test]
fn raw_tokens() {

View file

@ -78,8 +78,6 @@ pub use partial_closure::PartialClosure;
pub use rsx_call::*;
pub use template_body::TemplateBody;
pub use util::PrettyUnparse;
pub mod hot_reload;
#[cfg(feature = "hot_reload_traits")]

View file

@ -216,7 +216,7 @@ impl ToTokens for HotReloadFormattedSegment {
#[cfg(test)]
mod tests {
use super::*;
use crate::PrettyUnparse;
use prettier_please::PrettyUnparse;
#[test]
fn parses_lits() {

View file

@ -80,7 +80,7 @@ impl TextNode {
#[cfg(test)]
mod tests {
use super::*;
use crate::PrettyUnparse;
use prettier_please::PrettyUnparse;
#[test]
fn parses() {

View file

@ -19,20 +19,6 @@ pub(crate) fn intern<T: Eq + Hash + Send + Sync + ?Sized + 'static>(
s.into().as_ref()
}
/// These are just helpful methods for tests to pretty print the token stream - they are not used in the actual code
// #[cfg(test)]
pub trait PrettyUnparse {
fn pretty_unparse(&self) -> String;
}
// #[cfg(test)]
impl PrettyUnparse for TokenStream2 {
fn pretty_unparse(&self) -> String {
let parsed = syn::parse2::<syn::Expr>(self.clone()).unwrap();
prettier_please::unparse_expr(&parsed)
}
}
/// Parse a raw ident and return a new ident with the r# prefix added
pub fn parse_raw_ident(parse_buffer: &ParseBuffer) -> syn::Result<Ident> {
// First try to parse as a normal ident

View file

@ -1,7 +1,7 @@
use dioxus_rsx::CallBody;
use quote::ToTokens;
use dioxus_rsx::PrettyUnparse;
use prettier_please::PrettyUnparse;
#[test]
fn callbody_ctx() {