Skip to content

Commit ea49d1b

Browse files
sbernauerxeniape
andauthored
chore!: Enable and fix a few pedantic and nursery clippy lints (#1186)
* chore: First round of pedantic clippy lints * clippy::too_many_lines * clippy::implicit_hasher * Move clippy::doc_link_with_quotes * clippy::use_self * clippy::or_fun_call * clippy::derive_partial_eq_without_eq * Also run for all other crates * changelog * Move restriction lints * Silence explicit_deref_methods at calling location * Document why we can't deny needless_continue * Fix new code * Fix new code gp * Update CHANGELOG.md * Fix lints in new code * Apply suggestions from code review Co-authored-by: Xenia <xeniafischer@hotmail.de> --------- Co-authored-by: Xenia <xeniafischer@hotmail.de>
1 parent be90d5c commit ea49d1b

127 files changed

Lines changed: 1100 additions & 1034 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ x509-cert = { version = "0.2.5", features = ["builder"] }
9090
zeroize = "1.8.1"
9191

9292
[workspace.lints.clippy]
93+
# Enable all pedantic lints (with lower priority so individual lints can override)
94+
pedantic = { level = "deny", priority = -1 }
95+
96+
# Pedantic lints we don't enforce (yet)
97+
doc_markdown = "allow"
98+
missing_errors_doc = "allow"
99+
must_use_candidate = "allow"
100+
return_self_not_must_use = "allow"
101+
missing_panics_doc = "allow"
102+
cast_possible_truncation = "allow"
103+
float_cmp = "allow"
104+
cast_sign_loss = "allow"
105+
cast_precision_loss = "allow"
106+
unchecked_time_subtraction = "allow"
107+
# We should be able to deny this, but it lint's on code generated by darling, raised https://github.com/TedDriggs/darling/pull/429
108+
needless_continue = "allow"
109+
110+
# Additional nursery lints we enforce
111+
use_self = "deny"
112+
or_fun_call = "deny"
113+
derive_partial_eq_without_eq = "deny"
114+
unnecessary_struct_initialization = "deny"
115+
116+
# Additional restriction lints we enforce
93117
unwrap_in_result = "deny"
94118
unwrap_used = "deny"
95119
panic = "deny"

crates/k8s-version/src/api_version/darling.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ mod test {
1818
use super::*;
1919
use crate::{Level, Version};
2020

21-
fn parse_meta(tokens: proc_macro2::TokenStream) -> ::std::result::Result<syn::Meta, String> {
21+
fn parse_meta(tokens: &proc_macro2::TokenStream) -> syn::Meta {
2222
let attribute: syn::Attribute = syn::parse_quote!(#[#tokens]);
23-
Ok(attribute.meta)
23+
attribute.meta
2424
}
2525

2626
#[rstest]
2727
#[case(quote!(ignore = "extensions/v1beta1"), ApiVersion { group: Some("extensions".parse().unwrap()), version: Version { major: 1, level: Some(Level::Beta(1)) } })]
2828
#[case(quote!(ignore = "v1beta1"), ApiVersion { group: None, version: Version { major: 1, level: Some(Level::Beta(1)) } })]
2929
#[case(quote!(ignore = "v1"), ApiVersion { group: None, version: Version { major: 1, level: None } })]
3030
fn from_meta(#[case] input: proc_macro2::TokenStream, #[case] expected: ApiVersion) {
31-
let meta = parse_meta(input).expect("valid attribute tokens");
31+
let meta = parse_meta(&input);
3232
let api_version = ApiVersion::from_meta(&meta).expect("version must parse from attribute");
3333
assert_eq!(api_version, expected);
3434
}

crates/k8s-version/src/api_version/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod darling;
1212

1313
/// Error variants which can be encountered when creating a new [`ApiVersion`]
1414
/// from unparsed input.
15-
#[derive(Debug, PartialEq, Snafu)]
15+
#[derive(Debug, PartialEq, Eq, Snafu)]
1616
pub enum ParseApiVersionError {
1717
#[snafu(display("failed to parse version"))]
1818
ParseVersion { source: ParseVersionError },
@@ -87,10 +87,7 @@ impl ApiVersion {
8787
/// Try to create a new Kubernetes API version based on the unvalidated
8888
/// `group` string.
8989
pub fn try_new(group: Option<&str>, version: Version) -> Result<Self, ParseApiVersionError> {
90-
let group = group
91-
.map(|g| g.parse())
92-
.transpose()
93-
.context(ParseGroupSnafu)?;
90+
let group = group.map(str::parse).transpose().context(ParseGroupSnafu)?;
9491

9592
Ok(Self { group, version })
9693
}

crates/k8s-version/src/group.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static API_GROUP_REGEX: LazyLock<Regex> = LazyLock::new(|| {
1212

1313
/// Error variants which can be encountered when creating a new [`Group`] from
1414
/// unparsed input.
15-
#[derive(Debug, PartialEq, Snafu)]
15+
#[derive(Debug, PartialEq, Eq, Snafu)]
1616
pub enum ParseGroupError {
1717
#[snafu(display("group must not be empty"))]
1818
Empty,

crates/k8s-version/src/level/darling.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ mod tests {
1717

1818
use super::*;
1919

20-
fn parse_meta(tokens: proc_macro2::TokenStream) -> ::std::result::Result<syn::Meta, String> {
20+
fn parse_meta(tokens: &proc_macro2::TokenStream) -> syn::Meta {
2121
let attribute: syn::Attribute = syn::parse_quote!(#[#tokens]);
22-
Ok(attribute.meta)
22+
attribute.meta
2323
}
2424

2525
#[rstest]
2626
#[case(quote!(ignore = "alpha12"), Level::Alpha(12))]
2727
#[case(quote!(ignore = "alpha1"), Level::Alpha(1))]
2828
#[case(quote!(ignore = "beta1"), Level::Beta(1))]
2929
fn from_meta(#[case] input: proc_macro2::TokenStream, #[case] expected: Level) {
30-
let meta = parse_meta(input).expect("valid attribute tokens");
30+
let meta = parse_meta(&input);
3131
let version = Level::from_meta(&meta).expect("level must parse from attribute");
3232
assert_eq!(version, expected);
3333
}

crates/k8s-version/src/level/mod.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static LEVEL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
2222

2323
/// Error variants which can be encountered when creating a new [`Level`] from
2424
/// unparsed input.
25-
#[derive(Debug, PartialEq, Snafu)]
25+
#[derive(Debug, PartialEq, Eq, Snafu)]
2626
pub enum ParseLevelError {
2727
#[snafu(display("invalid level format, expected alpha<VERSION>|beta<VERSION>"))]
2828
InvalidFormat,
@@ -87,13 +87,13 @@ impl PartialOrd for Level {
8787
impl Ord for Level {
8888
fn cmp(&self, other: &Self) -> Ordering {
8989
match self {
90-
Level::Alpha(lhs) => match other {
91-
Level::Alpha(rhs) => lhs.cmp(rhs),
92-
Level::Beta(_) => Ordering::Less,
90+
Self::Alpha(lhs) => match other {
91+
Self::Alpha(rhs) => lhs.cmp(rhs),
92+
Self::Beta(_) => Ordering::Less,
9393
},
94-
Level::Beta(lhs) => match other {
95-
Level::Alpha(_) => Ordering::Greater,
96-
Level::Beta(rhs) => lhs.cmp(rhs),
94+
Self::Beta(lhs) => match other {
95+
Self::Alpha(_) => Ordering::Greater,
96+
Self::Beta(rhs) => lhs.cmp(rhs),
9797
},
9898
}
9999
}
@@ -103,12 +103,12 @@ impl<T> Add<T> for Level
103103
where
104104
T: Into<u64>,
105105
{
106-
type Output = Level;
106+
type Output = Self;
107107

108108
fn add(self, rhs: T) -> Self::Output {
109109
match self {
110-
Level::Alpha(lhs) => Level::Alpha(lhs + rhs.into()),
111-
Level::Beta(lhs) => Level::Beta(lhs + rhs.into()),
110+
Self::Alpha(lhs) => Self::Alpha(lhs + rhs.into()),
111+
Self::Beta(lhs) => Self::Beta(lhs + rhs.into()),
112112
}
113113
}
114114
}
@@ -119,8 +119,7 @@ where
119119
{
120120
fn add_assign(&mut self, rhs: T) {
121121
match self {
122-
Level::Alpha(lhs) => *lhs + rhs.into(),
123-
Level::Beta(lhs) => *lhs + rhs.into(),
122+
Self::Alpha(lhs) | Self::Beta(lhs) => *lhs + rhs.into(),
124123
};
125124
}
126125
}
@@ -129,12 +128,12 @@ impl<T> Sub<T> for Level
129128
where
130129
T: Into<u64>,
131130
{
132-
type Output = Level;
131+
type Output = Self;
133132

134133
fn sub(self, rhs: T) -> Self::Output {
135134
match self {
136-
Level::Alpha(lhs) => Level::Alpha(lhs - rhs.into()),
137-
Level::Beta(lhs) => Level::Beta(lhs - rhs.into()),
135+
Self::Alpha(lhs) => Self::Alpha(lhs - rhs.into()),
136+
Self::Beta(lhs) => Self::Beta(lhs - rhs.into()),
138137
}
139138
}
140139
}
@@ -145,17 +144,16 @@ where
145144
{
146145
fn sub_assign(&mut self, rhs: T) {
147146
match self {
148-
Level::Alpha(lhs) => *lhs - rhs.into(),
149-
Level::Beta(lhs) => *lhs - rhs.into(),
147+
Self::Alpha(lhs) | Self::Beta(lhs) => *lhs - rhs.into(),
150148
};
151149
}
152150
}
153151

154152
impl Display for Level {
155153
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
156154
match self {
157-
Level::Alpha(alpha) => write!(f, "alpha{}", alpha),
158-
Level::Beta(beta) => write!(f, "beta{}", beta),
155+
Self::Alpha(alpha) => write!(f, "alpha{alpha}"),
156+
Self::Beta(beta) => write!(f, "beta{beta}"),
159157
}
160158
}
161159
}
@@ -181,11 +179,11 @@ mod test {
181179

182180
#[apply(ord_cases)]
183181
fn ord(input: Level, other: Level, expected: Ordering) {
184-
assert_eq!(input.cmp(&other), expected)
182+
assert_eq!(input.cmp(&other), expected);
185183
}
186184

187185
#[apply(ord_cases)]
188186
fn partial_ord(input: Level, other: Level, expected: Ordering) {
189-
assert_eq!(input.partial_cmp(&other), Some(expected))
187+
assert_eq!(input.partial_cmp(&other), Some(expected));
190188
}
191189
}

crates/k8s-version/src/version/darling.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ mod tests {
1818
use super::*;
1919
use crate::Level;
2020

21-
fn parse_meta(tokens: proc_macro2::TokenStream) -> ::std::result::Result<syn::Meta, String> {
21+
fn parse_meta(tokens: &proc_macro2::TokenStream) -> syn::Meta {
2222
let attribute: syn::Attribute = syn::parse_quote!(#[#tokens]);
23-
Ok(attribute.meta)
23+
attribute.meta
2424
}
2525

2626
#[cfg(feature = "darling")]
@@ -30,7 +30,7 @@ mod tests {
3030
#[case(quote!(ignore = "v1beta1"), Version { major: 1, level: Some(Level::Beta(1)) })]
3131
#[case(quote!(ignore = "v1"), Version { major: 1, level: None })]
3232
fn from_meta(#[case] input: proc_macro2::TokenStream, #[case] expected: Version) {
33-
let meta = parse_meta(input).expect("valid attribute tokens");
33+
let meta = parse_meta(&input);
3434
let version = Version::from_meta(&meta).expect("version must parse from attribute");
3535
assert_eq!(version, expected);
3636
}

crates/k8s-version/src/version/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static VERSION_REGEX: LazyLock<Regex> = LazyLock::new(|| {
1818

1919
/// Error variants which can be encountered when creating a new [`Version`] from
2020
/// unparsed input.
21-
#[derive(Debug, PartialEq, Snafu)]
21+
#[derive(Debug, PartialEq, Eq, Snafu)]
2222
pub enum ParseVersionError {
2323
#[snafu(display(
2424
"invalid version format. Input is empty, contains non-ASCII characters or contains more than 63 characters"
@@ -153,16 +153,16 @@ mod test {
153153
#[case("", ParseVersionError::InvalidFormat)]
154154
fn invalid_version(#[case] input: &str, #[case] error: ParseVersionError) {
155155
let err = Version::from_str(input).expect_err("invalid Kubernetes version");
156-
assert_eq!(err, error)
156+
assert_eq!(err, error);
157157
}
158158

159159
#[apply(ord_cases)]
160160
fn ord(input: Version, other: Version, expected: Ordering) {
161-
assert_eq!(input.cmp(&other), expected)
161+
assert_eq!(input.cmp(&other), expected);
162162
}
163163

164164
#[apply(ord_cases)]
165165
fn partial_ord(input: Version, other: Version, expected: Ordering) {
166-
assert_eq!(input.partial_cmp(&other), Some(expected))
166+
assert_eq!(input.partial_cmp(&other), Some(expected));
167167
}
168168
}

crates/stackable-certs/src/ca/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ where
415415
/// Kubernetes [`Secret`]. Common keys are `ca.crt` and `ca.key`.
416416
#[instrument(name = "create_certificate_authority_from_k8s_secret", skip(secret))]
417417
pub fn from_secret(
418-
secret: Secret,
418+
secret: &Secret,
419419
key_certificate: &str,
420420
key_private_key: &str,
421421
) -> Result<Self, SecretError<S::Error>> {
@@ -424,27 +424,27 @@ where
424424
}
425425

426426
let data = secret.data.as_ref().with_context(|| NoSecretDataSnafu {
427-
secret: ObjectRef::from_obj(&secret),
427+
secret: ObjectRef::from_obj(secret),
428428
})?;
429429

430430
debug!("retrieving certificate data from secret via key {key_certificate:?}");
431431
let certificate_data =
432432
data.get(key_certificate)
433433
.with_context(|| NoCertificateDataSnafu {
434-
secret: ObjectRef::from_obj(&secret),
434+
secret: ObjectRef::from_obj(secret),
435435
})?;
436436

437437
let certificate = x509_cert::Certificate::load_pem_chain(&certificate_data.0)
438438
.with_context(|_| ReadChainSnafu {
439-
secret: ObjectRef::from_obj(&secret),
439+
secret: ObjectRef::from_obj(secret),
440440
})?
441441
.remove(0);
442442

443443
debug!("retrieving private key data from secret via key {key_certificate:?}");
444444
let private_key_data =
445445
data.get(key_private_key)
446446
.with_context(|| NoPrivateKeyDataSnafu {
447-
secret: ObjectRef::from_obj(&secret),
447+
secret: ObjectRef::from_obj(secret),
448448
})?;
449449

450450
let private_key_data =
@@ -472,15 +472,15 @@ where
472472
key_private_key: &str,
473473
client: Client,
474474
) -> Result<Self, SecretError<S::Error>> {
475-
let secret_api = Api::namespaced(client, &secret_ref.namespace);
475+
let secret_api: Api<Secret> = Api::namespaced(client, &secret_ref.namespace);
476476
let secret = secret_api
477477
.get(&secret_ref.name)
478478
.await
479479
.with_context(|_| GetSecretSnafu {
480480
secret_ref: secret_ref.to_owned(),
481481
})?;
482482

483-
Self::from_secret(secret, key_certificate, key_private_key)
483+
Self::from_secret(&secret, key_certificate, key_private_key)
484484
}
485485

486486
/// Returns the ca certificate.

crates/stackable-certs/src/keys/ecdsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::keys::CertificateKeypair;
1010

1111
pub type Result<T, E = Error> = std::result::Result<T, E>;
1212

13-
#[derive(Debug, PartialEq, Snafu)]
13+
#[derive(Debug, PartialEq, Eq, Snafu)]
1414
pub enum Error {
1515
#[snafu(context(false))]
1616
SerializeKeyToPem { source: x509_cert::spki::Error },

0 commit comments

Comments
 (0)