From d54c3827b886948d45013b9460d0e82dd94da386 Mon Sep 17 00:00:00 2001 From: KhizarImran Date: Sun, 2 Aug 2026 22:28:59 +0100 Subject: [PATCH] chore: fix clippy warnings and enforce clippy in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace four map_or(false, ..) calls in check_sl_tp with is_some_and, which reads closer to the intent ("there is a stop and price hit it"). CI now runs `cargo clippy --all-targets -- -D warnings` in place of `cargo check` — clippy is a superset, so this is more coverage in one fewer step, and -D warnings stops the lint debt building back up. --- .github/workflows/ci.yml | 5 ++++- src/broker.rs | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d79e5b..28db3c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,10 +11,13 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + components: clippy - uses: actions/setup-python@v5 with: python-version: "3.12" - - run: cargo check + # clippy does everything cargo check does, so it replaces it rather than adding to it + - run: cargo clippy --all-targets -- -D warnings - run: cargo test - run: python -m pip install ".[report]" - run: python -m unittest discover -s "$GITHUB_WORKSPACE/tests" diff --git a/src/broker.rs b/src/broker.rs index d360470..7ea77e0 100644 --- a/src/broker.rs +++ b/src/broker.rs @@ -23,8 +23,8 @@ impl Broker { let fill = { let p = &self.positions[i]; if p.is_long { - let sl_hit = p.stop_loss.map_or(false, |sl| bar.low <= sl); - let tp_hit = p.take_profit.map_or(false, |tp| bar.high >= tp); + let sl_hit = p.stop_loss.is_some_and(|sl| bar.low <= sl); + let tp_hit = p.take_profit.is_some_and(|tp| bar.high >= tp); if sl_hit { p.stop_loss } else if tp_hit { @@ -33,8 +33,8 @@ impl Broker { None } } else { - let sl_hit = p.stop_loss.map_or(false, |sl| bar.high >= sl); - let tp_hit = p.take_profit.map_or(false, |tp| bar.low <= tp); + let sl_hit = p.stop_loss.is_some_and(|sl| bar.high >= sl); + let tp_hit = p.take_profit.is_some_and(|tp| bar.low <= tp); if sl_hit { p.stop_loss } else if tp_hit {