From 09e14f1936eac39dc59d58ffe80212fcef2d1301 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 30 Jan 2024 18:17:45 -0800 Subject: [PATCH] Implement some clippy fixes --- Cargo.lock | 2 - Cargo.toml | 2 +- packages/core/Cargo.toml | 2 - packages/core/src/nodes.rs | 1 + packages/core/tests/diff_element.rs | 200 ++++++++++------------- packages/core/tests/event_propagation.rs | 2 +- packages/core/tests/lifecycle.rs | 2 +- packages/core/tests/task.rs | 4 +- packages/hooks/src/use_coroutine.rs | 11 +- packages/hooks/src/use_resource.rs | 8 +- packages/router/src/history/memory.rs | 2 +- 11 files changed, 103 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d032d18bc..9e54caefd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2466,8 +2466,6 @@ name = "dioxus-core" version = "0.4.3" dependencies = [ "dioxus", - "dioxus-core", - "dioxus-html", "dioxus-ssr", "futures-channel", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index 877dfd8cf..d0585be1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ version = "0.4.3" # dependencies that are shared across packages [workspace.dependencies] -dioxus = { path = "packages/dioxus", version = "0.4.0", default-features = false } +dioxus = { path = "packages/dioxus", version = "0.4.0" } dioxus-lib = { path = "packages/dioxus-lib", version = "0.4.0" } dioxus-core = { path = "packages/core", version = "0.4.2" } dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" } diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 6a164b36f..d5698a86d 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -25,8 +25,6 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] tokio = { workspace = true, features = ["full"] } dioxus = { workspace = true } -dioxus-core = { workspace = true } -dioxus-html = { workspace = true, features = ["serialize"] } pretty_assertions = "1.3.0" rand = "0.8.5" dioxus-ssr = { workspace = true } diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index 70dd3c246..4f150e3a4 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -738,6 +738,7 @@ impl PartialEq for AttributeValue { (Self::Bool(l0), Self::Bool(r0)) => l0 == r0, (Self::Listener(_), Self::Listener(_)) => true, (Self::Any(l0), Self::Any(r0)) => l0.as_ref().any_cmp(r0.as_ref()), + (Self::None, Self::None) => true, _ => false, } } diff --git a/packages/core/tests/diff_element.rs b/packages/core/tests/diff_element.rs index 534b59a86..afcda800d 100644 --- a/packages/core/tests/diff_element.rs +++ b/packages/core/tests/diff_element.rs @@ -1,6 +1,6 @@ use dioxus::dioxus_core::Mutation::*; +use dioxus::dioxus_core::{AttributeValue, ElementId, NoOpMutations}; use dioxus::prelude::*; -use dioxus_core::{AttributeValue, ElementId, NoOpMutations}; #[test] fn text_diff() { @@ -85,119 +85,99 @@ fn element_swap() { #[test] fn attribute_diff() { - // fn app() -> Element { - // let gen = cx.generation(); + fn app() -> Element { + let gen = generation(); - // // attributes have to be sorted by name - // let attrs = match gen % 5 { - // 0 => cx.bump().alloc([Attribute::new( - // "a", - // AttributeValue::Text("hello".into()), - // None, - // false, - // )]) as &[Attribute], - // 1 => cx.bump().alloc([ - // Attribute::new("a", AttributeValue::Text("hello".into()), None, false), - // Attribute::new("b", AttributeValue::Text("hello".into()), None, false), - // Attribute::new("c", AttributeValue::Text("hello".into()), None, false), - // ]) as &[Attribute], - // 2 => cx.bump().alloc([ - // Attribute::new("c", AttributeValue::Text("hello".into()), None, false), - // Attribute::new("d", AttributeValue::Text("hello".into()), None, false), - // Attribute::new("e", AttributeValue::Text("hello".into()), None, false), - // ]) as &[Attribute], - // 3 => cx.bump().alloc([Attribute::new( - // "d", - // AttributeValue::Text("world".into()), - // None, - // false, - // )]) as &[Attribute], - // _ => unreachable!(), - // }; + // attributes have to be sorted by name + let attrs = match gen % 5 { + 0 => vec![Attribute::new( + "a", + AttributeValue::Text("hello".into()), + None, + false, + )], + 1 => vec![ + Attribute::new("a", AttributeValue::Text("hello".into()), None, false), + Attribute::new("b", AttributeValue::Text("hello".into()), None, false), + Attribute::new("c", AttributeValue::Text("hello".into()), None, false), + ], + 2 => vec![ + Attribute::new("c", AttributeValue::Text("hello".into()), None, false), + Attribute::new("d", AttributeValue::Text("hello".into()), None, false), + Attribute::new("e", AttributeValue::Text("hello".into()), None, false), + ], + 3 => vec![Attribute::new( + "d", + AttributeValue::Text("world".into()), + None, + false, + )], + _ => unreachable!(), + }; - // cx.render(rsx!( - // div { - // ..*attrs, - // "hello" - // } - // )) - // } + rsx!( + div { + ..attrs, + "hello" + } + ) + } - // let mut vdom = VirtualDom::new(app); - // _ = vdom.rebuild(); + let mut vdom = VirtualDom::new(app); + vdom.rebuild(&mut NoOpMutations); - // vdom.mark_dirty(ScopeId::ROOT); - // assert_eq!( - // vdom.render_immediate().santize().edits, - // [ - // SetAttribute { - // name: "b", - // value: (&AttributeValue::Text("hello",)).into(), - // id: ElementId(1,), - // ns: None, - // }, - // SetAttribute { - // name: "c", - // value: (&AttributeValue::Text("hello",)).into(), - // id: ElementId(1,), - // ns: None, - // }, - // ] - // ); + vdom.mark_dirty(ScopeId::ROOT); + assert_eq!( + vdom.render_immediate_to_vec().santize().edits, + [ + SetAttribute { + name: "b", + value: (AttributeValue::Text("hello".into())), + id: ElementId(1,), + ns: None, + }, + SetAttribute { + name: "c", + value: (AttributeValue::Text("hello".into())), + id: ElementId(1,), + ns: None, + }, + ] + ); - // vdom.mark_dirty(ScopeId::ROOT); - // assert_eq!( - // vdom.render_immediate().santize().edits, - // [ - // SetAttribute { - // name: "a", - // value: (&AttributeValue::None).into(), - // id: ElementId(1,), - // ns: None, - // }, - // SetAttribute { - // name: "b", - // value: (&AttributeValue::None).into(), - // id: ElementId(1,), - // ns: None, - // }, - // SetAttribute { - // name: "d", - // value: (&AttributeValue::Text("hello",)).into(), - // id: ElementId(1,), - // ns: None, - // }, - // SetAttribute { - // name: "e", - // value: (&AttributeValue::Text("hello",)).into(), - // id: ElementId(1,), - // ns: None, - // }, - // ] - // ); + vdom.mark_dirty(ScopeId::ROOT); + assert_eq!( + vdom.render_immediate_to_vec().santize().edits, + [ + SetAttribute { name: "a", value: AttributeValue::None, id: ElementId(1,), ns: None }, + SetAttribute { name: "b", value: AttributeValue::None, id: ElementId(1,), ns: None }, + SetAttribute { + name: "d", + value: AttributeValue::Text("hello".into()), + id: ElementId(1,), + ns: None, + }, + SetAttribute { + name: "e", + value: AttributeValue::Text("hello".into()), + id: ElementId(1,), + ns: None, + }, + ] + ); - // vdom.mark_dirty(ScopeId::ROOT); - // assert_eq!( - // vdom.render_immediate().santize().edits, - // [ - // SetAttribute { - // name: "c", - // value: (&AttributeValue::None).into(), - // id: ElementId(1,), - // ns: None, - // }, - // SetAttribute { - // name: "d", - // value: (&AttributeValue::Text("world",)).into(), - // id: ElementId(1,), - // ns: None, - // }, - // SetAttribute { - // name: "e", - // value: (&AttributeValue::None).into(), - // id: ElementId(1,), - // ns: None, - // }, - // ] - // ); + vdom.mark_dirty(ScopeId::ROOT); + assert_eq!( + vdom.render_immediate_to_vec().santize().edits, + [ + SetAttribute { name: "c", value: AttributeValue::None, id: ElementId(1,), ns: None }, + SetAttribute { + name: "d", + value: AttributeValue::Text("world".into()), + id: ElementId(1,), + ns: None, + }, + SetAttribute { name: "e", value: AttributeValue::None, id: ElementId(1,), ns: None }, + ] + ); } diff --git a/packages/core/tests/event_propagation.rs b/packages/core/tests/event_propagation.rs index d7949b8a4..9be5a0b2a 100644 --- a/packages/core/tests/event_propagation.rs +++ b/packages/core/tests/event_propagation.rs @@ -6,7 +6,7 @@ static CLICKS: Mutex = Mutex::new(0); #[test] fn events_propagate() { - set_event_converter(Box::new(dioxus_html::SerializedHtmlEventConverter)); + set_event_converter(Box::new(dioxus::html::SerializedHtmlEventConverter)); let mut dom = VirtualDom::new(app); dom.rebuild(&mut dioxus_core::NoOpMutations); diff --git a/packages/core/tests/lifecycle.rs b/packages/core/tests/lifecycle.rs index 8ea5113b3..e0c4364d4 100644 --- a/packages/core/tests/lifecycle.rs +++ b/packages/core/tests/lifecycle.rs @@ -3,8 +3,8 @@ //! Tests for the lifecycle of components. use dioxus::dioxus_core::{ElementId, Mutation::*}; +use dioxus::html::SerializedHtmlEventConverter; use dioxus::prelude::*; -use dioxus_html::SerializedHtmlEventConverter; use std::rc::Rc; use std::sync::{Arc, Mutex}; diff --git a/packages/core/tests/task.rs b/packages/core/tests/task.rs index a5485987d..cab63eabd 100644 --- a/packages/core/tests/task.rs +++ b/packages/core/tests/task.rs @@ -94,7 +94,7 @@ async fn flushing() { fn app() -> Element { use_hook(|| { spawn(async move { - for x in 0..10 { + for _ in 0..10 { flush_sync().await; SEQUENCE.with(|s| s.borrow_mut().push(1)); } @@ -103,7 +103,7 @@ async fn flushing() { use_hook(|| { spawn(async move { - for x in 0..10 { + for _ in 0..10 { flush_sync().await; SEQUENCE.with(|s| s.borrow_mut().push(2)); } diff --git a/packages/hooks/src/use_coroutine.rs b/packages/hooks/src/use_coroutine.rs index cdfc56856..b63ebed1a 100644 --- a/packages/hooks/src/use_coroutine.rs +++ b/packages/hooks/src/use_coroutine.rs @@ -97,7 +97,7 @@ where /// See the docs for [`use_coroutine`] for more details. #[must_use] pub fn use_coroutine_handle() -> Coroutine { - use_hook(|| consume_context::>()) + use_hook(consume_context::>) } #[derive(PartialEq)] @@ -110,7 +110,7 @@ pub struct Coroutine { impl Coroutine { /// Get the underlying task handle pub fn task(&self) -> Task { - self.task.read().clone().unwrap() + (*self.task.read()).unwrap() } /// Send a message to the coroutine @@ -133,12 +133,9 @@ impl Coroutine { // manual impl since deriving doesn't work with generics impl Copy for Coroutine {} + impl Clone for Coroutine { fn clone(&self) -> Self { - Self { - tx: self.tx, - task: self.task, - needs_regen: self.needs_regen, - } + *self } } diff --git a/packages/hooks/src/use_resource.rs b/packages/hooks/src/use_resource.rs index eab7e7f0a..9a43c80b5 100644 --- a/packages/hooks/src/use_resource.rs +++ b/packages/hooks/src/use_resource.rs @@ -39,13 +39,9 @@ where let res = future::poll_fn(|cx| { // Set the effect stack properly - - // Poll the inner future - let ready = fut.poll_unpin(cx); - // add any dependencies to the effect stack that we need to watch when restarting the future - - ready + // Poll the inner future + fut.poll_unpin(cx) }) .await; diff --git a/packages/router/src/history/memory.rs b/packages/router/src/history/memory.rs index 4346fe985..d079aad76 100644 --- a/packages/router/src/history/memory.rs +++ b/packages/router/src/history/memory.rs @@ -52,7 +52,7 @@ where fn default() -> Self { Self { current: "/".parse().unwrap_or_else(|err| { - panic!("index route does not exist:\n{}\n use MemoryHistory::with_initial_path to set a custom path", err) + panic!("index route does not exist:\n{err}\n use MemoryHistory::with_initial_path to set a custom path") }), history: Vec::new(), future: Vec::new(),