From bd4fd02eff6b841cacb037ba5de5a28602dde30e Mon Sep 17 00:00:00 2001 From: Calli Date: Thu, 21 Nov 2024 21:17:17 +0100 Subject: [PATCH] fix: resolved some clippy warnings --- src/algorithm/cost_calculation.rs | 4 ++-- src/algorithm/drawing/grid.rs | 4 ++-- src/components/atoms/canvas_info_box.rs | 7 ++++--- src/components/atoms/text_with_edit.rs | 8 ++++---- src/components/atoms/toggle.rs | 2 +- src/components/canvas/dbl_click.rs | 6 ++---- src/components/canvas/mouse_up.rs | 10 +++++----- src/components/canvas/other.rs | 2 +- src/components/molecules/edge_info_box.rs | 13 ++++++++----- src/components/molecules/file_modal.rs | 8 ++------ src/components/molecules/station_info_box.rs | 9 ++++++--- src/components/organisms/canvas_controls.rs | 2 ++ src/components/organisms/sidebar.rs | 2 +- src/components/state/canvas.rs | 16 ++++++++-------- 14 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/algorithm/cost_calculation.rs b/src/algorithm/cost_calculation.rs index 21b1ea6..f8d5f03 100644 --- a/src/algorithm/cost_calculation.rs +++ b/src/algorithm/cost_calculation.rs @@ -266,7 +266,7 @@ fn diagonal_occupied( return map .get_station(station_id) .zip(diag_two.get_edge_id()) - .map_or(false, |(s, edge_id)| { + .is_some_and(|(s, edge_id)| { s.get_edges() .contains(&edge_id) }); @@ -276,7 +276,7 @@ fn diagonal_occupied( return map .get_station(station_id) .zip(diag_one.get_edge_id()) - .map_or(false, |(s, edge_id)| { + .is_some_and(|(s, edge_id)| { s.get_edges() .contains(&edge_id) }); diff --git a/src/algorithm/drawing/grid.rs b/src/algorithm/drawing/grid.rs index 8abd2f2..1111c01 100644 --- a/src/algorithm/drawing/grid.rs +++ b/src/algorithm/drawing/grid.rs @@ -18,13 +18,13 @@ pub fn draw_grid(canvas: &CanvasContext, state: CanvasState) { canvas, height, drawn_square_size, - f64::from(width) / drawn_square_size, + width / drawn_square_size, ); draw_horizontal_lines( canvas, width, drawn_square_size, - f64::from(height) / drawn_square_size, + height / drawn_square_size, ); canvas.stroke(); diff --git a/src/components/atoms/canvas_info_box.rs b/src/components/atoms/canvas_info_box.rs index a78440f..5538be4 100644 --- a/src/components/atoms/canvas_info_box.rs +++ b/src/components/atoms/canvas_info_box.rs @@ -7,6 +7,7 @@ use wasm_bindgen::JsCast; use crate::MapState; /// A generic canvas info box that others can be based upon. +#[allow(clippy::needless_pass_by_value)] // cannot be a reference because of the `Fn` trait #[component] pub fn CanvasInfoBox( /// The title of the info box, @@ -20,7 +21,7 @@ pub fn CanvasInfoBox( children: Option, ) -> impl IntoView where - S: ToString, + S: ToString + 'static, C: Fn() + 'static, { let info_box_ref: NodeRef = create_node_ref(); @@ -65,7 +66,7 @@ where // Offset by 15px to the left, aka 1rem - 1px let screen_pos = map_pos + sidebar_width + 2.0; - format!("{}px", screen_pos) + format!("{screen_pos}px") }; let top = move || { let map_pos = click_position @@ -79,7 +80,7 @@ where // Offset by 15px to the top, aka 1rem - 1px let screen_pos = map_pos + navbar_height + 2.0; - format!("{}px", screen_pos) + format!("{screen_pos}px") }; view! { diff --git a/src/components/atoms/text_with_edit.rs b/src/components/atoms/text_with_edit.rs index 1bd4c61..6caf323 100644 --- a/src/components/atoms/text_with_edit.rs +++ b/src/components/atoms/text_with_edit.rs @@ -23,7 +23,7 @@ where F: Fn(String) + Copy + 'static, { let (editing, set_editing) = create_signal(false); - let (text_input, set_text_input) = create_signal("".to_string()); + let (text_input, set_text_input) = create_signal(String::new()); // Generate the id for the input element and label. let edit_label_for_id = edit_label.clone(); @@ -50,13 +50,13 @@ where let on_done = move |_| { set_editing(false); on_edit(text_input.get()); - set_text_input("".to_string()); + set_text_input(String::new()); }; let on_submit = move |ev: KeyboardEvent| { if ev.key() == "Enter" { set_editing(false); on_edit(text_input.get()); - set_text_input("".to_string()); + set_text_input(String::new()); } }; @@ -115,7 +115,7 @@ where class="pointer-events-none absolute left-3 top-0 mb-0 max-w-[90%] origin-[0_0] truncate pt-[0.37rem] leading-[1.6] text-neutral-500 peer-focus:text-primary -translate-y-[0.9rem] scale-[0.8] dark:text-neutral-400 dark:peer-focus:text-primary" >{edit_label.clone()} - diff --git a/src/components/atoms/toggle.rs b/src/components/atoms/toggle.rs index d879c9d..251d73c 100644 --- a/src/components/atoms/toggle.rs +++ b/src/components/atoms/toggle.rs @@ -72,7 +72,7 @@ where id={id.clone()} _ref=input_ref on:input=parse_input - checked=move || value.map_or(false, |v| v()) + checked=move || value.is_some_and(|v| v()) prop:value=move || value.map(|v| v()) /> ) { state.update_canvas_state(|canvas| { canvas.set_size((height, width)); canvas.set_neighbor_sizes((nav_height, side_width)); - }) + }); }); } diff --git a/src/components/molecules/edge_info_box.rs b/src/components/molecules/edge_info_box.rs index 331006b..ff1193d 100644 --- a/src/components/molecules/edge_info_box.rs +++ b/src/components/molecules/edge_info_box.rs @@ -19,7 +19,12 @@ use crate::{ }; #[component] -fn LineInfo(line: Line, i: usize) -> impl IntoView { +fn LineInfo( + /// The line to show information about. + line: Line, + /// The index of the line in the list of lines. + i: usize, +) -> impl IntoView { let map_state = use_context::>().expect("to have found the global map state"); let (line, set_line) = create_signal(line); @@ -78,9 +83,7 @@ fn LineInfo(line: Line, i: usize) -> impl IntoView { if i > 0 {view!{
}.into_view()} else { - view!{ - <> - }.into_view()} + view!{}.into_view()} }

"Name:\n" impl IntoView { .get_clicked_on_edge() .map_or(Vec::new(), |e| { e.get_lines() - .into_iter() + .iter() .map(|l| { state .get_map() diff --git a/src/components/molecules/file_modal.rs b/src/components/molecules/file_modal.rs index 8a26a8b..756dee3 100644 --- a/src/components/molecules/file_modal.rs +++ b/src/components/molecules/file_modal.rs @@ -53,13 +53,9 @@ where let file_name = file.name(); let file_ext = Path::new(&file_name).extension(); - let file_type = if file_ext.map_or(false, |ext| { - ext.eq_ignore_ascii_case("json") - }) { + let file_type = if file_ext.is_some_and(|ext| ext.eq_ignore_ascii_case("json")) { FileType::Json - } else if file_ext.map_or(false, |ext| { - ext.eq_ignore_ascii_case("graphml") - }) { + } else if file_ext.is_some_and(|ext| ext.eq_ignore_ascii_case("graphml")) { FileType::GraphML } else { return; diff --git a/src/components/molecules/station_info_box.rs b/src/components/molecules/station_info_box.rs index 2c1bb9b..2d6be13 100644 --- a/src/components/molecules/station_info_box.rs +++ b/src/components/molecules/station_info_box.rs @@ -7,7 +7,10 @@ use crate::{ CanvasInfoBox, TextWithEdit, }, - models::StationID, + models::{ + Station, + StationID, + }, MapState, }; @@ -40,7 +43,7 @@ pub fn StationInfoBox() -> impl IntoView { map_state .get() .get_clicked_on_station() - .map_or("".to_string(), |s| { + .map_or(String::new(), |s| { logging::log!( "Name of station: {}: {}", s.get_id(), @@ -60,7 +63,7 @@ pub fn StationInfoBox() -> impl IntoView { map_state .get() .get_clicked_on_station() - .map(|s| s.get_id()) + .map(Station::get_id) }; let edit_station_name = move |station_id_opt: Option, new_name: String| { diff --git a/src/components/organisms/canvas_controls.rs b/src/components/organisms/canvas_controls.rs index 3df00e6..bae8ef1 100644 --- a/src/components/organisms/canvas_controls.rs +++ b/src/components/organisms/canvas_controls.rs @@ -3,6 +3,8 @@ // Async is used for futures, which are used in the worker, even though the algorithm itself is // sync. #![allow(clippy::unused_async)] +// This otherwise gets triggered by one in the wasm worker. +#![allow(unexpected_cfgs)] use ev::KeyboardEvent; use html::Div; diff --git a/src/components/organisms/sidebar.rs b/src/components/organisms/sidebar.rs index f07e109..15eac3c 100644 --- a/src/components/organisms/sidebar.rs +++ b/src/components/organisms/sidebar.rs @@ -114,7 +114,7 @@ pub fn Sidebar() -> impl IntoView {