فهرست منبع

Merge pull request #101 from alexkirsz/ci

CI: Enable clippy
Jonathan Kelley 3 سال پیش
والد
کامیت
29bf424

+ 20 - 20
.github/workflows/main.yml

@@ -15,7 +15,7 @@ jobs:
           override: true
       - uses: Swatinem/rust-cache@v1
       - run: sudo apt-get update
-      - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev libappindicator3-dev
+      - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev
       - uses: actions-rs/cargo@v1
         with:
           command: check
@@ -32,7 +32,7 @@ jobs:
           override: true
       - uses: Swatinem/rust-cache@v1
       - run: sudo apt-get update
-      - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev libappindicator3-dev
+      - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev
       - uses: actions-rs/cargo@v1
         with:
           command: test
@@ -55,21 +55,21 @@ jobs:
           command: fmt
           args: --all -- --check
 
-  # clippy:
-  #  name: Clippy
-  #  runs-on: ubuntu-latest
-  #  steps:
-  #    - uses: actions/checkout@v2
-  #    - uses: actions-rs/toolchain@v1
-  #      with:
-  #        profile: minimal
-  #        toolchain: stable
-  #        override: true
-  #    - uses: Swatinem/rust-cache@v1
-  #    - run: rustup component add clippy
-  #    - uses: actions-rs/cargo@v1
-  #      with:
-  #        command: clippy
-  #        args: -- -D warnings
-#
-# sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev libappindicator3-dev
+  clippy:
+    name: Clippy
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - uses: actions-rs/toolchain@v1
+        with:
+          profile: minimal
+          toolchain: stable
+          override: true
+      - uses: Swatinem/rust-cache@v1
+      - run: sudo apt-get update
+      - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev
+      - run: rustup component add clippy
+      - uses: actions-rs/cargo@v1
+        with:
+          command: clippy
+          args: -- -D warnings

+ 1 - 1
packages/core-macro/src/ifmt.rs

@@ -41,7 +41,7 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
         let mut out_format_literal = defer(&mut *out_format_literal, |it| {
             it.push(colon_or_closing_brace)
         });
-        let out_format_literal: &mut String = &mut *out_format_literal;
+        let out_format_literal: &mut String = *out_format_literal;
         let mut arg = s[i + 1..end].trim();
         if let Some("=") = arg.get(arg.len().saturating_sub(1)..) {
             assert_eq!(

+ 1 - 12
packages/core-macro/src/props/mod.rs

@@ -270,7 +270,7 @@ mod field_info {
         pub setter: SetterSettings,
     }
 
-    #[derive(Debug, Clone)]
+    #[derive(Debug, Clone, Default)]
     pub struct SetterSettings {
         pub doc: Option<syn::Expr>,
         pub skip: bool,
@@ -278,17 +278,6 @@ mod field_info {
         pub strip_option: bool,
     }
 
-    impl Default for SetterSettings {
-        fn default() -> Self {
-            Self {
-                doc: Default::default(),
-                skip: false,
-                auto_into: false,
-                strip_option: false,
-            }
-        }
-    }
-
     impl FieldBuilderAttr {
         pub fn with(mut self, attrs: &[syn::Attribute]) -> Result<Self, Error> {
             let mut skip_tokens = None;

+ 1 - 1
packages/core-macro/src/rsx/component.rs

@@ -181,7 +181,7 @@ impl Parse for ComponentField {
             return Ok(Self { name, content });
         }
 
-        if name.to_string() == "key" {
+        if name == "key" {
             let content = ContentField::ManExpr(input.parse()?);
             return Ok(Self { name, content });
         }

+ 1 - 0
packages/core/src/scopes.rs

@@ -745,6 +745,7 @@ impl ScopeState {
     ///     use_hook(|| Rc::new(RefCell::new(initial_value())))
     /// }
     /// ```
+    #[allow(clippy::mut_from_ref)]
     pub fn use_hook<'src, State: 'static>(
         &'src self,
         initializer: impl FnOnce(usize) -> State,

+ 9 - 1
packages/desktop/src/cfg.rs

@@ -4,11 +4,13 @@ use wry::{
     webview::WebView,
 };
 
+pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView);
+
 pub struct DesktopConfig<'a> {
     pub window: WindowBuilder,
     pub(crate) manual_edits: Option<Vec<DomEdit<'a>>>,
     pub(crate) pre_rendered: Option<String>,
-    pub(crate) event_handler: Option<Box<dyn Fn(&mut EventLoop<()>, &mut WebView)>>,
+    pub(crate) event_handler: Option<Box<DynEventHandlerFn>>,
 }
 
 impl<'a> DesktopConfig<'a> {
@@ -55,3 +57,9 @@ impl<'a> DesktopConfig<'a> {
         self
     }
 }
+
+impl<'a> Default for DesktopConfig<'a> {
+    fn default() -> Self {
+        Self::new()
+    }
+}

+ 1 - 1
packages/hooks/src/use_shared_state.rs

@@ -171,7 +171,7 @@ where
 ///
 ///
 ///
-pub fn use_context_provider<'a, T: 'static>(cx: &'a ScopeState, f: impl FnOnce() -> T) {
+pub fn use_context_provider<T: 'static>(cx: &ScopeState, f: impl FnOnce() -> T) {
     cx.use_hook(|_| {
         let state: ProvidedState<T> = RefCell::new(ProvidedStateInner {
             value: Rc::new(RefCell::new(f())),

+ 2 - 4
packages/hooks/src/usecoroutine.rs

@@ -15,10 +15,7 @@ let g = use_coroutine(&cx, || {
 
 
 */
-pub fn use_coroutine<'a, F>(
-    cx: &'a ScopeState,
-    create_future: impl FnOnce() -> F,
-) -> CoroutineHandle<'a>
+pub fn use_coroutine<F>(cx: &ScopeState, create_future: impl FnOnce() -> F) -> CoroutineHandle<'_>
 where
     F: Future<Output = ()> + 'static,
 {
@@ -98,6 +95,7 @@ impl Clone for CoroutineHandle<'_> {
 impl Copy for CoroutineHandle<'_> {}
 
 impl<'a> CoroutineHandle<'a> {
+    #[allow(clippy::needless_return)]
     pub fn start(&self) {
         if self.is_running() {
             return;

+ 2 - 4
packages/hooks/src/useref.rs

@@ -6,12 +6,10 @@ use std::{
 use dioxus_core::ScopeState;
 
 pub fn use_ref<'a, T: 'static>(cx: &'a ScopeState, f: impl FnOnce() -> T) -> &'a UseRef<T> {
-    let inner = cx.use_hook(|_| UseRef {
+    cx.use_hook(|_| UseRef {
         update_callback: cx.schedule_update(),
         value: Rc::new(RefCell::new(f())),
-    });
-
-    inner
+    })
 }
 
 pub struct UseRef<T> {

+ 1 - 1
packages/hooks/src/usesuspense.rs

@@ -27,7 +27,7 @@ pub fn use_suspense<R: 'static, F: Future<Output = R> + 'static>(
     });
 
     if let Some(value) = sus.value.as_ref() {
-        render(&value)
+        render(value)
     } else {
         // generate a placeholder node if the future isnt ready
         None

+ 1 - 1
packages/router/src/components/link.rs

@@ -46,7 +46,7 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
             id: format_args!("{}", cx.props.id.unwrap_or("")),
 
             prevent_default: "onclick",
-            onclick: move |_| service.push_route(cx.props.to.clone()),
+            onclick: move |_| service.push_route(cx.props.to),
 
             &cx.props.children
         }

+ 2 - 2
packages/router/src/components/route.rs

@@ -27,8 +27,8 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
     cx.use_hook(|_| {
         // create a bigger, better, longer route if one above us exists
         let total_route = match cx.consume_context::<RouteContext>() {
-            Some(ctx) => format!("{}", ctx.total_route.clone()),
-            None => format!("{}", cx.props.to.clone()),
+            Some(ctx) => ctx.total_route.to_string(),
+            None => cx.props.to.to_string(),
         };
 
         // provide our route context

+ 1 - 0
packages/router/src/lib.rs

@@ -1,3 +1,4 @@
+#![allow(warnings)]
 //! Dioxus-Router
 //!
 //! A simple match-based router and router service for most routing needs.

+ 5 - 4
packages/ssr/src/lib.rs

@@ -24,7 +24,7 @@ impl SsrRenderer {
 
     pub fn render_lazy<'a>(&'a mut self, f: LazyNodes<'a, '_>) -> String {
         let scope = self.vdom.base_scope();
-        let factory = NodeFactory::new(&scope);
+        let factory = NodeFactory::new(scope);
 
         let root = f.into_vnode(factory);
         format!(
@@ -38,6 +38,7 @@ impl SsrRenderer {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String {
     let vdom = VirtualDom::new(app);
     let scope: *const ScopeState = vdom.base_scope();
@@ -50,11 +51,11 @@ pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String {
     // When LazyNodes are provided, they are FnOnce, but do not come with a allocator selected to borrow from. The <'a>
     // lifetime is therefore longer than the lifetime of the allocator which doesn't exist... yet.
     //
-    // Therefore, we cast our local bump alloactor into right lifetime. This is okay because our usage of the bump arena
-    // is *definitely* shorter than the <'a> lifetime, and we return *owned* data - not borrowed data.
+    // Therefore, we cast our local bump allocator to the right lifetime. This is okay because our usage of the bump
+    // arena is *definitely* shorter than the <'a> lifetime, and we return *owned* data - not borrowed data.
     let scope = unsafe { &*scope };
 
-    let root = f.into_vnode(NodeFactory::new(&scope));
+    let root = f.into_vnode(NodeFactory::new(scope));
 
     format!(
         "{:}",