chore(clippy): enable and fix many stricter lints (#3783)

* chore(clippy): enable and fix many stricter lints

These ensure that the codebase uses more idiomatic, performant, and
concise language constructions.

* chore: make non-Clippy compiler warnings also deny by default
This commit is contained in:
Alejandro González
2025-06-14 02:10:12 +02:00
committed by GitHub
parent 301967d204
commit f84f8c1c2b
106 changed files with 542 additions and 760 deletions

View File

@@ -13,7 +13,6 @@ pub struct MultipartSegment {
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum MultipartSegmentData {
Text(String),
Binary(Vec<u8>),

View File

@@ -98,13 +98,12 @@ pub async fn upload_image_optimized(
let url = format!("{}/{}", cdn_url, upload_data.file_name);
Ok(UploadImageResult {
url: processed_upload_data
.clone()
.map(|x| format!("{}/{}", cdn_url, x.file_name))
.unwrap_or_else(|| url.clone()),
url: processed_upload_data.clone().map_or_else(
|| url.clone(),
|x| format!("{}/{}", cdn_url, x.file_name),
),
url_path: processed_upload_data
.map(|x| x.file_name)
.unwrap_or_else(|| upload_data.file_name.clone()),
.map_or_else(|| upload_data.file_name.clone(), |x| x.file_name),
raw_url: url,
raw_url_path: upload_data.file_name,
@@ -119,7 +118,7 @@ fn process_image(
min_aspect_ratio: Option<f32>,
) -> Result<(bytes::Bytes, String), ImageError> {
if content_type.to_lowercase() == "image/gif" {
return Ok((image_bytes.clone(), "gif".to_string()));
return Ok((image_bytes, "gif".to_string()));
}
let mut img = image::load_from_memory(&image_bytes)?;

View File

@@ -56,18 +56,15 @@ impl AsyncRateLimiter {
}
pub async fn check_rate_limit(&self, key: &str) -> RateLimitDecision {
let mut conn = match self.redis_pool.connect().await {
Ok(conn) => conn,
Err(_) => {
// If Redis is unavailable, allow the request but with reduced limit
return RateLimitDecision {
allowed: true,
limit: self.params.burst_size,
remaining: 1,
reset_after_ms: 60_000, // 1 minute
retry_after_ms: None,
};
}
let Ok(mut conn) = self.redis_pool.connect().await else {
// If Redis is unavailable, allow the request but with reduced limit
return RateLimitDecision {
allowed: true,
limit: self.params.burst_size,
remaining: 1,
reset_after_ms: 60_000, // 1 minute
retry_after_ms: None,
};
};
// Get current time in nanoseconds since UNIX epoch

View File

@@ -1,4 +1,4 @@
use std::sync::LazyLock;
use std::{fmt::Write, sync::LazyLock};
use itertools::Itertools;
use regex::Regex;
@@ -44,15 +44,17 @@ pub fn validation_errors_to_string(
ValidationErrorsKind::Field(errors) => {
if let Some(error) = errors.first() {
if let Some(adder) = adder {
output.push_str(&format!(
"Field {} {} failed validation with error: {}",
field, adder, error.code
));
write!(
&mut output,
"Field {field} {adder} failed validation with error: {}",
error.code
).unwrap();
} else {
output.push_str(&format!(
"Field {} failed validation with error: {}",
field, error.code
));
write!(
&mut output,
"Field {field} failed validation with error: {}",
error.code
).unwrap();
}
}