From a4b80dfb86c18e119cb2708431949bdf695f72c6 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 22 Feb 2024 08:43:44 -0700 Subject: [PATCH] Fix up Clippy and move lint config out of CI and into Cargo.toml --- .github/workflows/ci.yaml | 2 +- Cargo.toml | 9 +++++++++ src/main.rs | 38 ++++++++++++++++---------------------- src/pixie.rs | 4 ++-- src/save.rs | 5 ++--- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bcc880f..9a46b7d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -70,7 +70,7 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets --all-features -- -D warnings -A clippy::type_complexity -A clippy::too_many_arguments -W clippy::doc_markdown + args: --all-targets --all-features -- -D warnings # Run cargo fmt --all -- --check format: diff --git a/Cargo.toml b/Cargo.toml index e6aa5e3..556be20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,15 @@ rstar = "0.11" [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = { version = "0.3", features = ["console", "Window", "Storage"] } +[lints.clippy] +type_complexity = "allow" +too_many_arguments = "allow" +doc_markdown = "warn" +manual_let_else = "warn" +redundant_else = "warn" +match_same_arms = "warn" +semicolon_if_nothing_returned = "warn" +map_flatten = "warn" # Enable only a small amount of optimization in debug mode [profile.dev] diff --git a/src/main.rs b/src/main.rs index e21937f..5dec518 100644 --- a/src/main.rs +++ b/src/main.rs @@ -603,19 +603,15 @@ fn show_score_dialog_system( return; } - let level = match handles + let Some(level) = handles .levels .get(selected_level.0 as usize - 1) .and_then(|h| levels.get(h)) - { - Some(level) => level, - None => return, + else { + return; }; - let score = match score.0 { - Some(score) => score, - None => return, - }; + let Some(score) = score.0 else { return }; let num_stars = level .star_thresholds @@ -812,7 +808,7 @@ fn dismiss_score_dialog_button_system( } if let Ok(mut color) = q_node.get_single_mut() { - *color = Color::NONE.into() + *color = Color::NONE.into(); } } } @@ -1746,9 +1742,9 @@ fn drawing_mouse_movement_system( { connections .0 - .push(SegmentConnection::TryExtend(parent.get())) + .push(SegmentConnection::TryExtend(parent.get())); } else { - connections.0.push(SegmentConnection::Add(parent.get())) + connections.0.push(SegmentConnection::Add(parent.get())); } } if (line_state.start == *b && start_touching) @@ -1759,9 +1755,9 @@ fn drawing_mouse_movement_system( { connections .1 - .push(SegmentConnection::TryExtend(parent.get())) + .push(SegmentConnection::TryExtend(parent.get())); } else { - connections.1.push(SegmentConnection::Add(parent.get())) + connections.1.push(SegmentConnection::Add(parent.get())); } } } @@ -1805,7 +1801,7 @@ fn drawing_mouse_movement_system( adds.push(AddSegment { points: (*a, *b), connections, - }) + }); } if ok { @@ -2072,14 +2068,12 @@ fn update_cost_system( let mut cost = 0.0; for (segment, children) in q_segments.iter() { - let child = match children.first() { - Some(child) => child, - None => continue, + let Some(child) = children.first() else { + continue; }; - let layer = match q_colliders.get(*child) { - Ok(layer) => layer, - Err(_) => continue, + let Ok(layer) = q_colliders.get(*child) else { + continue; }; let multiplier = if layer.0 == 1 { @@ -2122,7 +2116,7 @@ fn update_cost_system( } else { text.sections[1].value = "".to_string(); } - text.sections[1].style.color = color::FINISHED_ROAD[line_draw.layer as usize - 1] + text.sections[1].style.color = color::FINISHED_ROAD[line_draw.layer as usize - 1]; } } @@ -2171,7 +2165,7 @@ fn update_score_text_system( if let Some(best) = best_scores.0.get(&selected_level.0) { text.sections[0].value = format!("Æ{best}"); } else { - text.sections[0].value = "Æ?".to_string() + text.sections[0].value = "Æ?".to_string(); } } } diff --git a/src/pixie.rs b/src/pixie.rs index 35b50c4..04fa360 100644 --- a/src/pixie.rs +++ b/src/pixie.rs @@ -430,7 +430,7 @@ pub fn move_pixies_system( if speed_diff > f32::EPSILON { pixie.current_speed += acceleration * delta; pixie.current_speed = pixie.current_speed.min(speed_limit); - pixie.driving_state = DrivingState::Accelerating + pixie.driving_state = DrivingState::Accelerating; } // move the pixie @@ -454,7 +454,7 @@ pub fn move_pixies_system( } else if prev_layer < current_layer && last_dist < PIXIE_RADIUS { transform.translation.z = layer::PIXIE - prev_layer as f32; } else { - transform.translation.z = layer::PIXIE - current_layer as f32 + transform.translation.z = layer::PIXIE - current_layer as f32; } } else { pixie.path_index += segments_traveled; diff --git a/src/save.rs b/src/save.rs index 6010418..7e65495 100644 --- a/src/save.rs +++ b/src/save.rs @@ -31,9 +31,8 @@ impl Plugin for SavePlugin { pub fn load_system(mut commands: Commands) { #[cfg(not(target_arch = "wasm32"))] { - let file = match std::fs::File::open(SAVE_FILE) { - Ok(f) => f, - Err(_) => return, + let Ok(file) = std::fs::File::open(SAVE_FILE) else { + return; }; let save_file: SaveFile = match ron::de::from_reader(file) {