From 49345b67ed5305ee822dd7b905837db8c9bf1326 Mon Sep 17 00:00:00 2001 From: archipelago Date: Sun, 2 Aug 2026 12:25:47 -0400 Subject: [PATCH] fix(openwrt): clear all 4 clippy lints so the CI -D warnings gate is real MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI (.github/workflows/ci.yml) already runs `cargo clippy --all-targets --all-features -- -D warnings`, but archipelago-openwrt emitted 4 warnings on a clean checkout, so the gate was red by default and enforced nothing. Fixed each lint at the source; no #[allow] added. - clippy::cmp_owned (wan.rs:146) — dropped the .to_string() that built an owned String purely to compare against "1"; &str == &str compares the same content. - clippy::unnecessary_sort_by (wifi_scan.rs:75, :177) — replaced sort_by(|a, b| b.signal.cmp(&a.signal)) with sort_by_key(|n| std::cmp::Reverse(n.signal)). Both are stable descending sorts on signal, so tie order is unchanged. Deliberately NOT -n.signal, which would misorder i32::MIN. - clippy::trim_split_whitespace (wifi_scan.rs:156) — removed the .trim() before .split_whitespace(); the latter already skips leading/trailing whitespace and never yields empty items, so parsing is unchanged. All three are semantics-preserving rewrites: no change to comparison results, sort ordering, or channel parsing. Co-Authored-By: Claude Opus 5 (1M context) --- core/openwrt/src/wan.rs | 2 +- core/openwrt/src/wifi_scan.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/openwrt/src/wan.rs b/core/openwrt/src/wan.rs index 11603170..fd63014b 100644 --- a/core/openwrt/src/wan.rs +++ b/core/openwrt/src/wan.rs @@ -143,7 +143,7 @@ pub fn get_wan_status(router: &Router) -> serde_json::Value { if [ \"$n\" = \"wan\" ]; then \ uci get firewall.@zone[$i].masq 2>/dev/null; break; \ fi; done"; - router.run_ok(script).unwrap_or_default().trim().to_string() == "1" + router.run_ok(script).unwrap_or_default().trim() == "1" }; info!("[{}] WAN status: configured={} ssid={:?} assoc={:?} sta_iface={:?} sta_state={:?} ip={:?} lan={} masq={}", diff --git a/core/openwrt/src/wifi_scan.rs b/core/openwrt/src/wifi_scan.rs index d16f0170..1278da74 100644 --- a/core/openwrt/src/wifi_scan.rs +++ b/core/openwrt/src/wifi_scan.rs @@ -72,7 +72,9 @@ fn parse_mtk_site_survey(output: &str) -> Result> { encryption: normalize_encryption(security), }); } - networks.sort_by(|a, b| b.signal.cmp(&a.signal)); + // Strongest signal first. `Reverse` keeps this a stable descending sort, + // identical in ordering (including ties) to the previous `sort_by` comparator. + networks.sort_by_key(|n| std::cmp::Reverse(n.signal)); Ok(networks) } @@ -153,7 +155,6 @@ fn parse_iwinfo_scan(output: &str) -> Result> { } else if line.contains("Channel:") && !line.starts_with("Encryption") { if let Some(ch_part) = line.split("Channel:").nth(1) { n.channel = ch_part - .trim() .split_whitespace() .next() .and_then(|s| s.parse().ok()) @@ -174,7 +175,9 @@ fn parse_iwinfo_scan(output: &str) -> Result> { } } - networks.sort_by(|a, b| b.signal.cmp(&a.signal)); + // Strongest signal first. `Reverse` keeps this a stable descending sort, + // identical in ordering (including ties) to the previous `sort_by` comparator. + networks.sort_by_key(|n| std::cmp::Reverse(n.signal)); Ok(networks) }