Skip to content

Commit 328ddad

Browse files
committed
refactor: use clippy pedantic
1 parent 682bcc6 commit 328ddad

File tree

33 files changed

+193
-128
lines changed

33 files changed

+193
-128
lines changed

Cargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors = ["ymgyt"]
77
categories = ["command-line-utilities"]
88
description = "terminal feed viewer"
99
edition = "2021"
10+
keywords = ["feed", "rss", "atom", "tui"]
1011
license = "MIT OR Apache-2.0"
1112
readme = "README"
1213
repository = "https://github.com/ymgyt/syndicationd"
@@ -29,3 +30,23 @@ tokio = { version = "1.35" }
2930
tracing = { version = "0.1.40" }
3031
tracing-subscriber = { version = "0.3.18", features = ["smallvec", "fmt", "ansi", "std", "env-filter", "time"], default-features = false }
3132
url = { version = "2.5.0" }
33+
34+
[workspace.lints.rust]
35+
unsafe_code = "forbid"
36+
37+
[workspace.lints.clippy]
38+
39+
# cargo
40+
cargo_common_metadata = "warn"
41+
multiple_crate_versions = "allow"
42+
negative_feature_names = "warn"
43+
redundant_feature_names = "warn"
44+
wildcard_dependencies = "warn"
45+
46+
# pedantic
47+
pedantic = "warn"
48+
49+
missing_errors_doc = "allow"
50+
missing_panics_doc = "allow"
51+
module_name_repetitions = "allow"
52+
must_use_candidate = "allow"

clippy.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# not landed yet
2+
# https://github.com/rust-lang/rust-clippy/issues/12164#issuecomment-1909934040
3+
# allowed-duplicate-crates = []

crates/synd_api/Cargo.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
[package]
22
authors.workspace = true
33
categories.workspace = true
4-
description = "syndicationd backend api"
54
edition.workspace = true
5+
keywords.workspace = true
66
license.workspace = true
7-
name = "synd_api"
7+
readme.workspace = true
88
repository.workspace = true
9-
version = "0.1.0"
9+
10+
description = "syndicationd backend api"
11+
name = "synd_api"
12+
version = "0.1.0"
1013

1114
[dependencies]
1215
anyhow = { workspace = true }
@@ -40,3 +43,6 @@ tracing-subscriber = { workspace = true }
4043

4144
# Enable graphql introspection
4245
introspection = []
46+
47+
[lints]
48+
workspace = true

crates/synd_api/src/client/github/client.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct GithubClient {
1414
impl GithubClient {
1515
const ENDPOINT: &'static str = "https://api.github.com/graphql";
1616

17-
/// Construct GithubClient.
17+
/// Construct `GithubClient`.
1818
pub fn new() -> anyhow::Result<Self> {
1919
let client = reqwest::ClientBuilder::new()
2020
.user_agent(config::USER_AGENT)
@@ -27,10 +27,11 @@ impl GithubClient {
2727

2828
pub async fn authenticate(&self, access_token: &str) -> anyhow::Result<String> {
2929
let variables = query::authenticate::Variables {};
30-
let req = query::Authenticate::build_query(variables);
31-
let res: query::authenticate::ResponseData = self.request(access_token, &req).await?;
30+
let request = query::Authenticate::build_query(variables);
31+
let response: query::authenticate::ResponseData =
32+
self.request(access_token, &request).await?;
3233

33-
Ok(res.viewer.email)
34+
Ok(response.viewer.email)
3435
}
3536

3637
async fn request<Body, ResponseData>(
@@ -42,7 +43,7 @@ impl GithubClient {
4243
Body: Serialize + ?Sized,
4344
ResponseData: DeserializeOwned + Debug,
4445
{
45-
let mut auth_header = HeaderValue::try_from(format!("bearer {}", access_token))?;
46+
let mut auth_header = HeaderValue::try_from(format!("bearer {access_token}"))?;
4647
auth_header.set_sensitive(true);
4748

4849
let res: Response<ResponseData> = self

crates/synd_api/src/gql/object/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Feed {
9696

9797
/// Undering feed specification
9898
async fn r#type(&self) -> FeedType {
99-
self.0.meta().r#type().into()
99+
self.0.meta().r#type().clone().into()
100100
}
101101

102102
/// Feed title
@@ -115,6 +115,7 @@ impl Feed {
115115
}
116116

117117
/// Feed entries
118+
#[allow(clippy::cast_sign_loss)]
118119
async fn entries(
119120
&self,
120121
#[graphql(default = 5)] first: Option<i32>,
@@ -126,6 +127,7 @@ impl Feed {
126127
FeedEntryConnectionName,
127128
FeedEntryEdgeName,
128129
> {
130+
#[allow(clippy::cast_sign_loss)]
129131
let first = first.unwrap_or(5).max(0) as usize;
130132
let meta = self.0.meta();
131133
let entries = self

crates/synd_api/src/gql/query.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl Subscription {
2525
after: Option<String>,
2626
#[graphql(default = 20)] first: Option<i32>,
2727
) -> Result<Connection<String, object::Feed>> {
28+
#[allow(clippy::cast_sign_loss)]
2829
let first = first.unwrap_or(10).min(100) as usize;
2930
let has_prev = after.is_some();
3031
let input = FetchSubscribedFeedsInput {
@@ -57,6 +58,7 @@ impl Subscription {
5758
after: Option<String>,
5859
#[graphql(default = 20)] first: Option<i32>,
5960
) -> Result<Connection<id::EntryId, Entry<'cx>>> {
61+
#[allow(clippy::cast_sign_loss)]
6062
let first = first.unwrap_or(20).min(200) as usize;
6163
let has_prev = after.is_some();
6264
let input = FetchEntriesInput {

crates/synd_api/src/persistence/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl MemoryDatastore {
4141
.iter()
4242
.map(|feed| persistence::types::FeedSubscription {
4343
user_id: "me".into(),
44-
url: feed.to_string(),
44+
url: (*feed).to_string(),
4545
})
4646
.collect(),
4747
),

crates/synd_api/src/principal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl User {
3030

3131
email.hash(&mut s);
3232
let id = s.finish();
33-
let id = format!("{:016x}", id);
33+
let id = format!("{id:016x}");
3434

3535
User { id, email }
3636
}

crates/synd_api/src/serve/layer/audit.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ impl Audit {
4848
pub const OPERATION: &'static str = "operation";
4949
pub const RESULT: &'static str = "result";
5050

51+
/// # Panics
52+
/// panic when directive is invalid
5153
pub fn directive() -> Directive {
5254
let directive = format!("{emit}=info", emit = Self::EMIT_TARGET);
5355

5456
directive.parse().expect("Invalid directive")
5557
}
5658
}
5759

58-
/// Create AuditLayer
60+
/// Create `AuditLayer`
5961
pub fn layer<S>() -> impl Layer<S>
6062
where
6163
S: Subscriber + for<'span> LookupSpan<'span>,
@@ -72,18 +74,18 @@ impl AuditFilter {
7274
Self {}
7375
}
7476

75-
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
77+
fn is_enabled(meta: &Metadata<'_>) -> bool {
7678
meta.target() == Audit::TARGET
7779
}
7880
}
7981

8082
impl<S> layer::Filter<S> for AuditFilter {
8183
fn enabled(&self, meta: &Metadata<'_>, _cx: &Context<'_, S>) -> bool {
82-
self.is_enabled(meta)
84+
Self::is_enabled(meta)
8385
}
8486

8587
fn callsite_enabled(&self, meta: &'static Metadata<'static>) -> Interest {
86-
if self.is_enabled(meta) {
88+
if Self::is_enabled(meta) {
8789
Interest::always()
8890
} else {
8991
Interest::never()
@@ -138,7 +140,7 @@ impl<S> Layer<S> for AuditLayer
138140
where
139141
S: Subscriber + for<'span> LookupSpan<'span>,
140142
{
141-
/// If new span is audit root span, create AuditContext and insert to extensions.
143+
/// If new span is audit root span, create `AuditContext` and insert to extensions.
142144
fn on_new_span(&self, attrs: &Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
143145
if attrs.metadata().name() != Audit::SPAN_ROOT_NAME {
144146
return;

crates/synd_api/src/serve/layer/authenticate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where
7070
self.set(AuthenticateFuture::ServiceCall { service_fut });
7171
self.poll(cx)
7272
}
73-
Poll::Ready(Err(_)) => Poll::Ready(Ok(StatusCode::UNAUTHORIZED.into_response())),
73+
Poll::Ready(Err(())) => Poll::Ready(Ok(StatusCode::UNAUTHORIZED.into_response())),
7474
Poll::Pending => Poll::Pending,
7575
},
7676
AuthFutureProj::ServiceCall { service_fut } => service_fut.poll(cx),

crates/synd_api/src/usecase/fetch_subscribed_feeds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ impl Usecase for FetchSubscribedFeeds {
7676
let feeds = self.fetch_feed.fetch_feeds_parallel(urls).await;
7777

7878
// TODO: return failed feeds
79-
let (feeds, errors): (Vec<_>, Vec<_>) = feeds.into_iter().partition(|r| r.is_ok());
79+
let (feeds, errors): (Vec<_>, Vec<_>) = feeds.into_iter().partition(Result::is_ok);
8080

8181
if !errors.is_empty() {
8282
tracing::error!("{errors:?}");
8383
}
8484

85-
let feeds = feeds.into_iter().map(|r| r.unwrap()).collect();
85+
let feeds = feeds.into_iter().map(Result::unwrap).collect();
8686

8787
Ok(Output {
8888
output: FetchSubscribedFeedsOutput { feeds },

crates/synd_authn/Cargo.toml

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[package]
2-
authors.workspace = true
3-
categories.workspace = true
4-
description.workspace = true
5-
edition.workspace = true
6-
license.workspace = true
7-
name = "synd_authn"
8-
readme.workspace = true
9-
repository.workspace = true
10-
version = "0.1.0"
2+
authors.workspace = true
3+
categories.workspace = true
4+
edition.workspace = true
5+
keywords.workspace = true
6+
license.workspace = true
7+
readme.workspace = true
8+
repository.workspace = true
9+
10+
description = "syndicationd authentication lib"
11+
name = "synd_authn"
12+
version = "0.1.0"
1113

1214
[dependencies]
1315
anyhow = { workspace = true }
@@ -18,3 +20,6 @@ serde = { workspace = true, features = ["derive"] }
1820
serde_json = { workspace = true }
1921
tokio = { workspace = true, features = ["time"] }
2022
tracing = { workspace = true }
23+
24+
[lints]
25+
workspace = true

crates/synd_authn/src/device_flow/github.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::device_flow::{
1111

1212
const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
1313

14-
/// https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow
14+
/// <https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow>
1515
#[derive(Clone)]
1616
pub struct DeviceFlow {
1717
client: Client,
@@ -37,6 +37,7 @@ impl DeviceFlow {
3737
}
3838
}
3939

40+
#[must_use]
4041
pub fn with_endpoint(self, endpoint: &'static str) -> Self {
4142
Self {
4243
endpoint: Some(endpoint),
@@ -110,14 +111,15 @@ impl DeviceFlow {
110111
match response.status() {
111112
StatusCode::OK => {
112113
let full = response.bytes().await?;
113-
match serde_json::from_slice::<DeviceAccessTokenResponse>(&full) {
114-
Ok(response) => break response,
115-
Err(_) => continue_or_abort!(full),
114+
if let Ok(response) = serde_json::from_slice::<DeviceAccessTokenResponse>(&full)
115+
{
116+
break response;
116117
}
118+
continue_or_abort!(full);
117119
}
118120
StatusCode::BAD_REQUEST => {
119121
let full = response.bytes().await?;
120-
continue_or_abort!(full)
122+
continue_or_abort!(full);
121123
}
122124
other => {
123125
let error_msg = response.text().await.unwrap_or_default();

crates/synd_authn/src/device_flow/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use serde::{Deserialize, Serialize};
55

66
pub mod github;
77

8-
/// https://datatracker.ietf.org/doc/html/rfc8628#section-3.1
8+
/// <https://datatracker.ietf.org/doc/html/rfc8628#section-3.1>
99
#[derive(Serialize, Deserialize, Debug)]
1010
pub struct DeviceAuthorizationRequest<'s> {
1111
pub client_id: Cow<'s, str>,
1212
pub scope: Cow<'s, str>,
1313
}
1414

15-
/// https://datatracker.ietf.org/doc/html/rfc8628#section-3.2
15+
/// <https://datatracker.ietf.org/doc/html/rfc8628#section-3.2>
1616
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1717
pub struct DeviceAuthorizationResponse {
1818
/// device verification code
@@ -57,7 +57,7 @@ impl<'s> DeviceAccessTokenRequest<'s> {
5757
}
5858

5959
/// Successful Response
60-
/// https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
60+
/// <https://datatracker.ietf.org/doc/html/rfc6749#section-5.1>
6161
#[derive(Deserialize, Debug)]
6262
pub struct DeviceAccessTokenResponse {
6363
/// the access token issued by the authorization server
@@ -67,7 +67,7 @@ pub struct DeviceAccessTokenResponse {
6767
pub expires_in: Option<i64>,
6868
}
6969

70-
/// https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
70+
/// <https://datatracker.ietf.org/doc/html/rfc6749#section-5.2>
7171
#[derive(Deserialize, Debug)]
7272
pub struct DeviceAccessTokenErrorResponse {
7373
pub error: DeviceAccessTokenErrorCode,
@@ -96,9 +96,9 @@ pub enum DeviceAccessTokenErrorCode {
9696
}
9797

9898
impl DeviceAccessTokenErrorCode {
99-
/// The "authorization_pending" and "slow_down" error codes define particularly unique behavior, as they indicate that the OAuth client should continue to poll the token endpoint by repeating the token request (implementing the precise behavior defined above)
99+
/// The `authorization_pending` and `slow_down` error codes define particularly unique behavior, as they indicate that the OAuth client should continue to poll the token endpoint by repeating the token request (implementing the precise behavior defined above)
100100
pub fn should_continue_to_poll(&self) -> bool {
101-
use DeviceAccessTokenErrorCode::*;
101+
use DeviceAccessTokenErrorCode::{AuthorizationPending, SlowDown};
102102
*self == AuthorizationPending || *self == SlowDown
103103
}
104104
}

crates/synd_feed/Cargo.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
[package]
22
authors.workspace = true
33
categories.workspace = true
4-
description = "Library to handle syndication spec"
54
edition.workspace = true
5+
keywords.workspace = true
66
license.workspace = true
7-
name = "synd_feed"
7+
readme.workspace = true
88
repository.workspace = true
9-
version = "0.1.0"
9+
10+
description = "Library to handle syndication spec"
11+
name = "synd_feed"
12+
version = "0.1.0"
1013

1114
[dependencies]
1215
anyhow = { workspace = true }
@@ -19,3 +22,6 @@ reqwest = { workspace = true, features = ["stream"] }
1922
thiserror = "1.0.56"
2023
tokio = { workspace = true }
2124
tracing = { workspace = true }
25+
26+
[lints]
27+
workspace = true

0 commit comments

Comments
 (0)