diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8966397..d392f3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,17 +23,17 @@ jobs: toolchain: nightly profile: minimal override: true - components: rustfmt + components: rustfmt, clippy - name: Cache uses: Swatinem/rust-cache@v2 - name: Check function count badge run: python3 docs/generate_count_badge.py --check - name: Check formatting run: cargo fmt --check -# - name: Check if the README is up to date. -# run: | -# cargo install cargo-rdme -# cargo rdme --check + - name: Clippy check + uses: auguwu/clippy-action@1.1.2 + with: + args: --all-features --tests -- -D warnings - name: Run tests run: cargo test --all-features diff --git a/Cargo.toml b/Cargo.toml index 6f3e62f..652ceb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ homepage = "https://leptos-use.rs" leptos = "0.3.0" wasm-bindgen = "0.2.86" js-sys = "0.3.63" -default-struct-builder = "0.2.0" +default-struct-builder = "0.2.1" num = { version = "0.4.0", optional = true } serde = { version = "1.0.163", optional = true } serde_json = { version = "1.0.96", optional = true } diff --git a/README.md b/README.md index 1e87082..8a45845 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +
+

Leptos-Use – Collection of essential Leptos utilities diff --git a/src/storage/use_storage.rs b/src/storage/use_storage.rs index ad50b56..a3deac2 100644 --- a/src/storage/use_storage.rs +++ b/src/storage/use_storage.rs @@ -200,7 +200,7 @@ where Ok(ref serialized) => match store.get_item(&k) { Ok(old_value) => { if old_value.as_ref() != Some(serialized) { - if let Err(e) = store.set_item(&k, &serialized) { + if let Err(e) = store.set_item(&k, serialized) { on_err(UseStorageError::StorageAccessError(e)); } else { let mut event_init = web_sys::CustomEventInit::new(); diff --git a/src/use_event_listener.rs b/src/use_event_listener.rs index 58ca7a2..779b38e 100644 --- a/src/use_event_listener.rs +++ b/src/use_event_listener.rs @@ -149,7 +149,7 @@ where }; let cleanup_prev_el = Rc::clone(&cleanup_prev_element); - let closure = closure_js.clone(); + let closure = closure_js; create_effect(cx, move |_| { cleanup_prev_el.borrow()(); diff --git a/src/use_media_query.rs b/src/use_media_query.rs index 05cfdf4..1002941 100644 --- a/src/use_media_query.rs +++ b/src/use_media_query.rs @@ -38,7 +38,7 @@ pub fn use_media_query(cx: Scope, query: impl Into>) -> Sign let (matches, set_matches) = create_signal(cx, false); let media_query: Rc>> = Rc::new(RefCell::new(None)); - let remove_listener: Rc>>> = Rc::new(RefCell::new(None)); + let remove_listener: RemoveListener = Rc::new(RefCell::new(None)); let rem_listener = Rc::clone(&remove_listener); @@ -88,3 +88,5 @@ pub fn use_media_query(cx: Scope, query: impl Into>) -> Sign matches.into() } + +type RemoveListener = Rc>>>; diff --git a/src/use_mouse.rs b/src/use_mouse.rs index d97e88e..8ae7c8c 100644 --- a/src/use_mouse.rs +++ b/src/use_mouse.rs @@ -174,7 +174,7 @@ where cx, target.clone(), touchmove, - touch_handler.clone(), + touch_handler, event_listener_options.clone(), ); if options.reset_on_touch_ends { diff --git a/src/use_resize_observer.rs b/src/use_resize_observer.rs index ad1e1f5..1c15f0e 100644 --- a/src/use_resize_observer.rs +++ b/src/use_resize_observer.rs @@ -150,10 +150,10 @@ impl Default for UseResizeObserverOptions { } } -impl Into for UseResizeObserverOptions { - fn into(self) -> web_sys::ResizeObserverOptions { +impl From for web_sys::ResizeObserverOptions { + fn from(val: UseResizeObserverOptions) -> Self { let mut options = web_sys::ResizeObserverOptions::new(); - options.box_(self.box_); + options.box_(val.box_); options } } diff --git a/src/use_scroll.rs b/src/use_scroll.rs index ff25e4c..6543d23 100644 --- a/src/use_scroll.rs +++ b/src/use_scroll.rs @@ -210,8 +210,7 @@ where let scroll = scroll_to.clone(); let set_x = Box::new(move |x| scroll(Some(x), None)); - let scroll = scroll_to.clone(); - let set_y = Box::new(move |y| scroll(None, Some(y))); + let set_y = Box::new(move |y| scroll_to(None, Some(y))); let (is_scrolling, set_is_scrolling) = create_signal(cx, false); @@ -475,9 +474,9 @@ pub enum ScrollBehavior { Smooth, } -impl Into for ScrollBehavior { - fn into(self) -> web_sys::ScrollBehavior { - match self { +impl From for web_sys::ScrollBehavior { + fn from(val: ScrollBehavior) -> Self { + match val { ScrollBehavior::Auto => web_sys::ScrollBehavior::Auto, ScrollBehavior::Smooth => web_sys::ScrollBehavior::Smooth, } diff --git a/src/utils/filters/mod.rs b/src/utils/filters/mod.rs index 679e721..5d33059 100644 --- a/src/utils/filters/mod.rs +++ b/src/utils/filters/mod.rs @@ -62,12 +62,8 @@ impl FilterOptions { R: 'static, { match self { - FilterOptions::Debounce { ms, options } => { - Box::new(debounce_filter(ms.clone(), *options)) - } - FilterOptions::Throttle { ms, options } => { - Box::new(throttle_filter(ms.clone(), *options)) - } + FilterOptions::Debounce { ms, options } => Box::new(debounce_filter(*ms, *options)), + FilterOptions::Throttle { ms, options } => Box::new(throttle_filter(*ms, *options)), FilterOptions::None => Box::new(|invoke: Box>| { Rc::new(RefCell::new(Some(invoke()))) }), diff --git a/src/watch.rs b/src/watch.rs index 560d7d6..a16bc5e 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -160,14 +160,14 @@ where create_effect(cx, move |did_run_before| { if !is_active() { - return (); + return; } let deps_value = deps(); if !options.immediate && did_run_before.is_none() { prev_deps_value.replace(Some(deps_value)); - return (); + return; } cur_deps_value.replace(Some(deps_value.clone())); @@ -181,8 +181,6 @@ where prev_callback_value.replace(callback_value); prev_deps_value.replace(Some(deps_value)); - - () }); move || {