From 9474ad54cc2b1577e3c753521380683c140d6653 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Thu, 14 Mar 2024 22:40:23 -0700 Subject: [PATCH] Make clippy happy --- packages/cli/src/server/mod.rs | 19 +++++------- packages/core/src/virtual_dom.rs | 2 +- .../src/hot_reload/hot_reloading_file_map.rs | 31 ++++++++----------- packages/web/src/hot_reload.rs | 2 +- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/packages/cli/src/server/mod.rs b/packages/cli/src/server/mod.rs index c624e2770b..332fbf909e 100644 --- a/packages/cli/src/server/mod.rs +++ b/packages/cli/src/server/mod.rs @@ -119,7 +119,7 @@ fn watch_event( let mut needs_full_rebuild = false; if let Some(hot_reload) = &hot_reload { - hotreload_files(hot_reload, &mut needs_full_rebuild, &event, &config); + hotreload_files(hot_reload, &mut needs_full_rebuild, &event, config); } if needs_full_rebuild { @@ -142,7 +142,7 @@ fn full_rebuild( #[allow(clippy::redundant_clone)] print_console_info( - &config, + config, PrettierOptions { changed: event.paths.clone(), warnings: res.warnings, @@ -186,10 +186,7 @@ fn hotreload_files( // If the file was hotreloaded, update the file map in place match rsx_file_map.update_rsx(path, &config.crate_dir) { Ok(UpdateResult::UpdatedRsx(msgs)) => { - messages.extend( - msgs.into_iter() - .map(|msg| HotReloadMsg::UpdateTemplate(msg)), - ); + messages.extend(msgs.into_iter().map(HotReloadMsg::UpdateTemplate)); } // If the file was not updated, we need to do a full rebuild @@ -227,7 +224,7 @@ fn hotreload_files( } fn hotreload_file( - path: &PathBuf, + path: &Path, config: &CrateConfig, rsx_file_map: &std::sync::MutexGuard<'_, FileMap>, messages: &mut Vec, @@ -282,14 +279,14 @@ fn hotreload_file( } fn attempt_css_reload( - path: &PathBuf, + path: &Path, asset_dir: PathBuf, rsx_file_map: &std::sync::MutexGuard<'_, FileMap>, config: &CrateConfig, messages: &mut Vec, ) -> Option<()> { // If the path is not in the asset directory, return - if !path.starts_with(&asset_dir) { + if !path.starts_with(asset_dir) { return None; } @@ -312,7 +309,7 @@ fn attempt_css_reload( Some(()) } -fn local_path_of_asset(path: &PathBuf) -> Option { +fn local_path_of_asset(path: &Path) -> Option { path.file_name()?.to_str()?.to_string().parse().ok() } @@ -323,7 +320,7 @@ pub(crate) trait Platform { fn rebuild(&mut self, config: &CrateConfig) -> Result; } -fn is_backup_file(path: &PathBuf) -> bool { +fn is_backup_file(path: &Path) -> bool { // If there's a tilde at the end of the file, it's a backup file if let Some(name) = path.file_name() { if let Some(name) = name.to_str() { diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 203efa41cf..0a21446680 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -559,7 +559,7 @@ impl VirtualDom { } if let Some(RenderReturn::Ready(sync)) = scope.try_root_node() { - if check_node_for_templates(&sync, template) { + if check_node_for_templates(sync, template) { dirty.push(ScopeId(id)); } } diff --git a/packages/rsx/src/hot_reload/hot_reloading_file_map.rs b/packages/rsx/src/hot_reload/hot_reloading_file_map.rs index 055bff682d..7d7edc7452 100644 --- a/packages/rsx/src/hot_reload/hot_reloading_file_map.rs +++ b/packages/rsx/src/hot_reload/hot_reloading_file_map.rs @@ -121,7 +121,7 @@ impl FileMap { // If the cached file is not a valid rsx file, rebuild the project, forcing errors // TODO: in theory the error is simply in the RsxCallbody. We could attempt to parse it using partial expansion // And collect out its errors instead of giving up to a full rebuild - let old = syn::parse_file(&*old_cached.raw).map_err(|_e| HotreloadError::Parse)?; + let old = syn::parse_file(&old_cached.raw).map_err(|_e| HotreloadError::Parse)?; let instances = match diff_rsx(&syntax, &old) { // If the changes were just some rsx, we can just update the template @@ -199,7 +199,7 @@ impl FileMap { }; // update the cached file - old_cached.templates.insert(template.name, template.clone()); + old_cached.templates.insert(template.name, template); // Track any new assets old_cached @@ -214,26 +214,21 @@ impl FileMap { fn populate_assets(template: Template) -> HashSet { fn collect_assetlike_attrs(node: &TemplateNode, asset_urls: &mut HashSet) { - match node { - TemplateNode::Element { - attrs, children, .. - } => { - for attr in attrs.iter() { - match attr { - TemplateAttribute::Static { name, value, .. } => { - if *name == "src" || *name == "href" { - asset_urls.insert(PathBuf::from(*value)); - } - } - _ => {} + if let TemplateNode::Element { + attrs, children, .. + } = node + { + for attr in attrs.iter() { + if let TemplateAttribute::Static { name, value, .. } = attr { + if *name == "src" || *name == "href" { + asset_urls.insert(PathBuf::from(*value)); } } + } - for child in children.iter() { - collect_assetlike_attrs(child, asset_urls); - } + for child in children.iter() { + collect_assetlike_attrs(child, asset_urls); } - _ => {} } } diff --git a/packages/web/src/hot_reload.rs b/packages/web/src/hot_reload.rs index aeb889a170..9906ca9712 100644 --- a/packages/web/src/hot_reload.rs +++ b/packages/web/src/hot_reload.rs @@ -53,7 +53,7 @@ pub(crate) fn init() -> UnboundedReceiver