From 2a9160836bb87fdea3ae891563b0169c68d1c2ab Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 16:53:03 +0000 Subject: fix: resolve all fmt and clippy warnings Main lib (src/): - Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration) - Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting) - Replace .or_insert_with(RelaySyncNeeds::default) with .or_default() - Replace manual div_ceil implementations with .div_ceil(100) Test code (tests/): - Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...)) - Remove needless borrows in fetch_metrics() calls - Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module grasp-audit: - Apply cargo fmt to fix formatting --- src/nostr/builder.rs | 22 ++++++++-------------- src/nostr/policy/announcement.rs | 7 +++++-- src/nostr/policy/mod.rs | 3 +-- src/nostr/policy/pr_event.rs | 2 +- src/nostr/policy/related.rs | 7 ++----- src/nostr/policy/state.rs | 7 +++++-- 6 files changed, 22 insertions(+), 26 deletions(-) (limited to 'src/nostr') diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 2284c18..c9bd1e1 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs @@ -16,8 +16,8 @@ use crate::nostr::events::{ KIND_REPOSITORY_STATE, }; use crate::nostr::policy::{ - AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, RelatedEventPolicy, - ReferenceResult, StatePolicy, StateResult, + AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, + RelatedEventPolicy, StatePolicy, StateResult, }; /// Type alias for the shared database used by the relay @@ -77,7 +77,9 @@ impl Nip34WritePolicy { match RepositoryAnnouncement::from_event(event.clone()) { Ok(announcement) => { // Try to create bare repository if it doesn't exist - if let Err(e) = self.announcement_policy.ensure_bare_repository(&announcement) + if let Err(e) = self + .announcement_policy + .ensure_bare_repository(&announcement) { tracing::warn!( "Failed to create bare repository for {}: {}", @@ -145,22 +147,14 @@ impl Nip34WritePolicy { Ok(_state) => { // Process state alignment asynchronously if let Err(e) = self.state_policy.process_state_event(event).await { - tracing::warn!( - "Failed to process state event {}: {}", - event_id_str, - e - ); + tracing::warn!("Failed to process state event {}: {}", event_id_str, e); } tracing::debug!("Accepted repository state: {}", event_id_str); PolicyResult::Accept } Err(e) => { - tracing::warn!( - "Failed to parse repository state {}: {}", - event_id_str, - e - ); + tracing::warn!("Failed to parse repository state {}: {}", event_id_str, e); // Still accept the event even if we can't parse it // The validation passed, so it's structurally valid PolicyResult::Accept @@ -348,4 +342,4 @@ pub fn create_relay(config: &Config) -> Result { database, write_policy, }) -} \ No newline at end of file +} diff --git a/src/nostr/policy/announcement.rs b/src/nostr/policy/announcement.rs index 8d30baf..353738b 100644 --- a/src/nostr/policy/announcement.rs +++ b/src/nostr/policy/announcement.rs @@ -72,7 +72,10 @@ impl AnnouncementPolicy { /// Create a bare git repository if it doesn't exist /// Path format: //.git - pub fn ensure_bare_repository(&self, announcement: &RepositoryAnnouncement) -> Result<(), String> { + pub fn ensure_bare_repository( + &self, + announcement: &RepositoryAnnouncement, + ) -> Result<(), String> { let repo_path = self.ctx.git_data_path.join(announcement.repo_path()); // Check if repository already exists @@ -154,4 +157,4 @@ impl AnnouncementPolicy { Ok(false) } -} \ No newline at end of file +} diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs index 6d67394..19db5f6 100644 --- a/src/nostr/policy/mod.rs +++ b/src/nostr/policy/mod.rs @@ -5,7 +5,6 @@ /// - `StatePolicy` - State event validation + ref alignment /// - `PrEventPolicy` - PR/PR Update validation /// - `RelatedEventPolicy` - Forward/backward reference checking - mod announcement; mod pr_event; mod related; @@ -38,4 +37,4 @@ impl PolicyContext { git_data_path: git_data_path.into(), } } -} \ No newline at end of file +} diff --git a/src/nostr/policy/pr_event.rs b/src/nostr/policy/pr_event.rs index fee9a2a..53da369 100644 --- a/src/nostr/policy/pr_event.rs +++ b/src/nostr/policy/pr_event.rs @@ -195,4 +195,4 @@ impl PrEventPolicy { Ok(None) } } -} \ No newline at end of file +} diff --git a/src/nostr/policy/related.rs b/src/nostr/policy/related.rs index 1937ca7..7ce87db 100644 --- a/src/nostr/policy/related.rs +++ b/src/nostr/policy/related.rs @@ -169,10 +169,7 @@ impl RelatedEventPolicy { /// Check if any events exist in database /// Returns the first matching event ID found, or None if none match - async fn find_accepted_event( - &self, - event_ids: &[EventId], - ) -> Result, String> { + async fn find_accepted_event(&self, event_ids: &[EventId]) -> Result, String> { if event_ids.is_empty() { return Ok(None); } @@ -273,4 +270,4 @@ impl RelatedEventPolicy { Ok(false) } -} \ No newline at end of file +} diff --git a/src/nostr/policy/state.rs b/src/nostr/policy/state.rs index 5692bd8..43349e2 100644 --- a/src/nostr/policy/state.rs +++ b/src/nostr/policy/state.rs @@ -239,7 +239,10 @@ impl StatePolicy { } // Build repository path: //.git - let repo_path = self.ctx.git_data_path.join(announcement.repo_path().clone()); + let repo_path = self + .ctx + .git_data_path + .join(announcement.repo_path().clone()); owner_repos.push((announcement, repo_path)); } @@ -416,4 +419,4 @@ impl StatePolicy { result } -} \ No newline at end of file +} -- cgit v1.2.3