Skip to content

Commit 4b2c37d

Browse files
committed
Add rustfmt and clippy CI gate on pinned 1.84.0 and make the crate rustfmt-clean
1 parent 44735d5 commit 4b2c37d

5 files changed

Lines changed: 40 additions & 19 deletions

File tree

.github/workflows/rust.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ jobs:
2323
command: test
2424
args: --all-features --features ci
2525

26+
lint:
27+
name: Rustfmt and Clippy
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Install pinned toolchain with rustfmt and clippy
34+
uses: actions-rs/toolchain@v1
35+
with:
36+
profile: minimal
37+
toolchain: 1.84.0
38+
override: true
39+
components: rustfmt, clippy
40+
41+
- name: Check formatting
42+
uses: actions-rs/cargo@v1
43+
with:
44+
command: fmt
45+
args: --all -- --check
46+
47+
- name: Clippy
48+
uses: actions-rs/cargo@v1
49+
with:
50+
command: clippy
51+
args: --all-targets --all-features -- -D warnings
52+
2653
coverage:
2754
name: Code Coverage
2855
runs-on: ubuntu-latest

src/domain/followee_notification_factory.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ impl FolloweeNotificationFactory {
109109
pub fn should_delete(&mut self) -> bool {
110110
// If it has been empty for a day, it's ok to delete
111111
self.follow_changes.is_empty()
112-
&& self.emptied_at.is_none_or(|emptied_at| {
113-
Instant::now().duration_since(emptied_at) >= ONE_DAY
114-
})
112+
&& self
113+
.emptied_at
114+
.is_none_or(|emptied_at| Instant::now().duration_since(emptied_at) >= ONE_DAY)
115115
}
116116

117117
pub fn no_followers(&self) -> bool {
@@ -171,20 +171,14 @@ impl FolloweeNotificationFactory {
171171
}
172172

173173
// Check if we need to remove any follow changes
174-
let to_remove = self
175-
.follow_changes
176-
.len()
177-
.saturating_sub(self.max_changes);
174+
let to_remove = self.follow_changes.len().saturating_sub(self.max_changes);
178175
if to_remove > 0 {
179176
// First, remove all untrusted follow changes by retaining only trusted ones
180177
self.follow_changes
181178
.retain(|_, follow_change| follow_change.is_trusted());
182179

183180
// If we still need to remove more to stay under the limit, drain from the beginning (oldest entries)
184-
let remaining_to_remove = self
185-
.follow_changes
186-
.len()
187-
.saturating_sub(self.max_changes);
181+
let remaining_to_remove = self.follow_changes.len().saturating_sub(self.max_changes);
188182
if remaining_to_remove > 0 {
189183
// OrderMap preserves insertion order, so the first items are the oldest
190184
self.follow_changes.drain(0..remaining_to_remove);

src/domain/notification_factory.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,7 @@ mod tests {
609609
// Insert trusted changes exceeding the max
610610
for _ in 0..max_changes + 3 {
611611
let follower = Keys::generate().public_key();
612-
let change =
613-
FollowChange::new_followed(*NOW, follower, followee).with_trusted(true);
612+
let change = FollowChange::new_followed(*NOW, follower, followee).with_trusted(true);
614613
factory.insert(change.into());
615614
}
616615
assert_eq!(factory.follow_changes_len(), max_changes + 3);
@@ -644,8 +643,7 @@ mod tests {
644643
// Insert mix of trusted and untrusted
645644
for trusted in [false, true, false, true, false] {
646645
let follower = Keys::generate().public_key();
647-
let change =
648-
FollowChange::new_followed(*NOW, follower, followee).with_trusted(trusted);
646+
let change = FollowChange::new_followed(*NOW, follower, followee).with_trusted(trusted);
649647
factory.insert(change.into());
650648
}
651649

src/http_server.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ mod router;
44
mod trust_policy;
55

66
use crate::{
7-
config::Settings,
8-
recommendation_queue::RecommendationQueue,
9-
relay_subscriber::GetEventsOf,
7+
config::Settings, recommendation_queue::RecommendationQueue, relay_subscriber::GetEventsOf,
108
repo::RepoTrait,
119
};
1210
use anyhow::{Context, Result};

src/http_server/router.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ mod tests {
234234
let repo = Arc::new(MockRepo);
235235
let result_cache = moka::future::Cache::builder().build();
236236
let (queue, _receiver) = RecommendationQueue::new(repo.clone(), result_cache, 16);
237-
Arc::new(AppState::new(repo, Arc::new(MockNostrClient), Arc::new(queue)))
237+
Arc::new(AppState::new(
238+
repo,
239+
Arc::new(MockNostrClient),
240+
Arc::new(queue),
241+
))
238242
}
239243

240244
/// Regression test for the discovery document being served outside the

0 commit comments

Comments
 (0)