From 984214801049932957837455e2a115de800b0923 Mon Sep 17 00:00:00 2001 From: extrawurst <776816+extrawurst@users.noreply.github.com> Date: Wed, 26 Mar 2025 01:20:38 +0100 Subject: [PATCH] fix clippy and check it on ci (#18) --- .github/workflows/ci.yml | 24 ++++++++++---------- .github/workflows/ci_debug.yml | 40 ++++++++++++++++++++++++++++++++++ Cargo.toml | 6 ++++- justfile | 8 ++++++- src/backpack/backpack_ui.rs | 16 +++++--------- src/backpack/mod.rs | 1 - src/camera.rs | 2 +- src/control/controller.rs | 6 ++--- src/control/controls.rs | 9 ++++---- src/cutscene.rs | 4 ++-- src/gates.rs | 7 ++---- src/heads_ui.rs | 1 - src/npc.rs | 2 +- src/shooting.rs | 12 ++-------- 14 files changed, 85 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/ci_debug.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 650b1ae..3e0868e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: branches: ["master"] jobs: - debug: + ci: runs-on: [self-hosted, linux] steps: - uses: actions/checkout@v4 @@ -23,16 +23,18 @@ jobs: packages: libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev version: 1.0 + - name: Formatting + run: | + cargo fmt --check + + - name: Lints + run: | + cargo clippy + - name: Build run: | - cargo build --locked --target=x86_64-unknown-linux-gnu - - - name: Archive - run: | - cp target/x86_64-unknown-linux-gnu/debug/hedz_reloaded hedz_reloaded - tar -czf steamos-debug.tar.gz hedz_reloaded + cargo build - - uses: actions/upload-artifact@v4 - with: - name: steamos-debug.tar.gz - path: ./steamos-debug.tar.gz \ No newline at end of file + - name: Lints + run: | + cargo test diff --git a/.github/workflows/ci_debug.yml b/.github/workflows/ci_debug.yml new file mode 100644 index 0000000..b45bf73 --- /dev/null +++ b/.github/workflows/ci_debug.yml @@ -0,0 +1,40 @@ +name: ci_debug + +on: + workflow_dispatch: # Enables manual triggers + +jobs: + debug: + runs-on: [self-hosted, linux] + steps: + - uses: actions/checkout@v4 + - uses: cargo-bins/cargo-binstall@main + - uses: extractions/setup-just@v1 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy, rustfmt + + - name: "Install and cache dependencies (Linux)" + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev + version: 1.0 + + - name: Build + run: | + cargo build --locked --target=x86_64-unknown-linux-gnu + + - name: Lints + run: | + cargo clippy + + - name: Archive + run: | + cp target/x86_64-unknown-linux-gnu/debug/hedz_reloaded hedz_reloaded + tar -czf steamos-debug.tar.gz hedz_reloaded + + - uses: actions/upload-artifact@v4 + with: + name: steamos-debug.tar.gz + path: ./steamos-debug.tar.gz diff --git a/Cargo.toml b/Cargo.toml index ec62fb4..b76e91d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ avian3d = { version = "0.2.1", default-features = false, features = [ "parry-f32", "collider-from-mesh", "bevy_scene", - "bevy_picking", # todo: Consider if this one is necessary + "bevy_picking", # todo: Consider if this one is necessary "parallel", ] } bevy = "0.15.3" @@ -27,3 +27,7 @@ bevy_sprite3d = "4.0.0" rand = "0.8.5" bevy-inspector-egui = { version = "0.30", optional = true } bevy_polyline = "0.11.0" + +[lints.clippy] +too_many_arguments = "allow" +type_complexity = "allow" diff --git a/justfile b/justfile index 1a260b7..3c2b5a1 100644 --- a/justfile +++ b/justfile @@ -6,4 +6,10 @@ tb_setup_mac: ln -s $(pwd)/trenchbroom/hedz/GameConfig.cfg "$HOME/Library/Application Support/TrenchBroom/games/hedz/GameConfig.cfg" | true dbg: - RUST_BACKTRACE=1 cargo r --features dbg \ No newline at end of file + RUST_BACKTRACE=1 cargo r --features dbg + +check: + cargo fmt --check + cargo b + cargo test + cargo clippy diff --git a/src/backpack/backpack_ui.rs b/src/backpack/backpack_ui.rs index 380303b..3315a2d 100644 --- a/src/backpack/backpack_ui.rs +++ b/src/backpack/backpack_ui.rs @@ -280,17 +280,13 @@ fn swap_head_inputs( } let mut changed = false; - if action == BackpackAction::Left { - if state.current_slot > 0 { - state.current_slot -= 1; - changed = true; - } + if action == BackpackAction::Left && state.current_slot > 0 { + state.current_slot -= 1; + changed = true; } - if action == BackpackAction::Right { - if state.current_slot < state.count.saturating_sub(1) { - state.current_slot += 1; - changed = true; - } + if action == BackpackAction::Right && state.current_slot < state.count.saturating_sub(1) { + state.current_slot += 1; + changed = true; } if action == BackpackAction::Swap { commands.trigger(BackbackSwapEvent(state.current_slot)); diff --git a/src/backpack/mod.rs b/src/backpack/mod.rs index 8d43737..feaac3f 100644 --- a/src/backpack/mod.rs +++ b/src/backpack/mod.rs @@ -34,7 +34,6 @@ pub fn plugin(app: &mut App) { fn setup(mut commands: Commands) { commands.insert_resource(Backpack { heads: (0usize..HEAD_COUNT) - .into_iter() .map(|i| BackpackHead { head: i, health: 1., diff --git a/src/camera.rs b/src/camera.rs index 0d2ee83..27c2688 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -66,7 +66,7 @@ fn startup(mut commands: Commands) { fn update_look_around(controls: Res, mut cam_state: ResMut) { let look_around = - controls.keyboard_state.view_mode || controls.gamepad_state.map_or(false, |g| g.view_mode); + controls.keyboard_state.view_mode || controls.gamepad_state.is_some_and(|g| g.view_mode); if look_around != cam_state.look_around { cam_state.look_around = look_around; diff --git a/src/control/controller.rs b/src/control/controller.rs index 8490ec9..3c14cdc 100644 --- a/src/control/controller.rs +++ b/src/control/controller.rs @@ -239,10 +239,8 @@ fn set_movement_flag(mut player_movement: ResMut, controls: Res< if direction.length_squared() < deadzone { player_movement.any_direction = false; } - } else { - if direction.length_squared() > deadzone { - player_movement.any_direction = true; - } + } else if direction.length_squared() > deadzone { + player_movement.any_direction = true; } } diff --git a/src/control/controls.rs b/src/control/controls.rs index 2ac0fe5..63cc577 100644 --- a/src/control/controls.rs +++ b/src/control/controls.rs @@ -62,7 +62,7 @@ fn gamepad_controls( if rotate < 0.5 - EPSILON { 40. * (rotate - 0.5) } else if rotate > 0.5 + EPSILON { - 40. * (rotate - 0.5) + -40. * (rotate - 0.5) } else { 0. }, @@ -189,8 +189,8 @@ fn mouse_click(mut events: EventReader, mut commands: Commands fn gamepad_connections(mut evr_gamepad: EventReader) { for ev in evr_gamepad.read() { - match ev { - GamepadEvent::Connection(connection) => match &connection.connection { + if let GamepadEvent::Connection(connection) = ev { + match &connection.connection { GamepadConnection::Connected { name, vendor_id, @@ -204,8 +204,7 @@ fn gamepad_connections(mut evr_gamepad: EventReader) { GamepadConnection::Disconnected => { info!("Lost connection with gamepad: {:?}", connection.gamepad); } - }, - _ => {} + } } } } diff --git a/src/cutscene.rs b/src/cutscene.rs index 08f965a..c3d774c 100644 --- a/src/cutscene.rs +++ b/src/cutscene.rs @@ -48,8 +48,8 @@ fn on_start_cutscene( let move_end = cutscene_movement .iter() .find(|(_, _, target)| cutscene == target.target.clone().unwrap_or_default()) - .map(|(t, _, _)| t.clone()) - .unwrap_or_else(|| t.clone()); + .map(|(t, _, _)| *t) + .unwrap_or_else(|| *t); let Some((target, _)) = cam_target.iter().find(|(_, camera_target)| { camera_target.targetname == target.target.clone().unwrap_or_default() diff --git a/src/gates.rs b/src/gates.rs index f90f1ee..0be85ff 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -14,7 +14,7 @@ fn on_key(trigger: Trigger, mut commands: Commands) { let entities: HashSet<_> = vec!["fence_01", "fence_02"] .into_iter() - .map(|s| String::from(s)) + .map(String::from) .collect(); commands.trigger(PlaySound::Gate); @@ -23,10 +23,7 @@ fn on_key(trigger: Trigger, mut commands: Commands) { "fence_shaft" => { commands.trigger(StartCutscene("cutscene_02".to_string())); - let entities: HashSet<_> = vec!["fence_shaft"] - .into_iter() - .map(|s| String::from(s)) - .collect(); + let entities: HashSet<_> = vec!["fence_shaft"].into_iter().map(String::from).collect(); commands.trigger(PlaySound::Gate); commands.trigger(TriggerMovableEvent(entities)); diff --git a/src/heads_ui.rs b/src/heads_ui.rs index f13e41a..655d3ed 100644 --- a/src/heads_ui.rs +++ b/src/heads_ui.rs @@ -75,7 +75,6 @@ fn setup(mut commands: Commands, asset_server: Res) { }); let heads = (0usize..HEAD_COUNT) - .into_iter() .map(|i| asset_server.load(format!("ui/heads/{}.png", head_id_to_str(i)))) .collect(); diff --git a/src/npc.rs b/src/npc.rs index a67e614..73897ba 100644 --- a/src/npc.rs +++ b/src/npc.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, usize}; +use std::collections::HashMap; use crate::{ heads_ui::HEAD_COUNT, keys::KeySpawn, player::head_id_to_str, sounds::PlaySound, diff --git a/src/shooting.rs b/src/shooting.rs index 83d02c2..bf49522 100644 --- a/src/shooting.rs +++ b/src/shooting.rs @@ -151,11 +151,7 @@ fn enemy_hit( continue; } - let enemy_entity = query_npc - .contains(*e1) - .then(|| *e1) - .or_else(|| Some(*e2)) - .unwrap(); + let enemy_entity = if query_npc.contains(*e1) { *e1 } else { *e2 }; commands.entity(enemy_entity).trigger(Hit { damage: 20 }); } @@ -199,11 +195,7 @@ fn shot_collision( continue; } - let shot_entity = query_shot - .contains(*e1) - .then(|| *e1) - .or_else(|| Some(*e2)) - .unwrap(); + let shot_entity = if query_shot.contains(*e1) { *e1 } else { *e2 }; let shot_pos = query_shot.get(shot_entity).unwrap().1.translation;