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

@@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize};
use sha1::Digest;
use sqlx::PgPool;
use std::collections::HashMap;
use std::fmt::Write;
use std::io::{Cursor, Read};
use std::time::Duration;
use zip::ZipArchive;
@@ -33,29 +34,31 @@ impl ModerationMessages {
}
pub fn markdown(&self, auto_mod: bool) -> String {
let mut str = "".to_string();
let mut str = String::new();
for message in &self.messages {
str.push_str(&format!("## {}\n", message.header()));
str.push_str(&format!("{}\n", message.body()));
str.push('\n');
write!(&mut str, "## {}\n{}\n\n", message.header(), message.body())
.unwrap();
}
for (version_num, messages) in &self.version_specific {
for message in messages {
str.push_str(&format!(
"## Version {}: {}\n",
write!(
&mut str,
"### Version {}: {}\n{}\n\n",
version_num,
message.header()
));
str.push_str(&format!("{}\n", message.body()));
str.push('\n');
message.header(),
message.body()
)
.unwrap();
}
}
if auto_mod {
str.push_str("<hr />\n\n");
str.push_str("🤖 This is an automated message generated by AutoMod (BETA). If you are facing issues, please [contact support](https://support.modrinth.com).");
str.push_str(
"<hr />\n\n\
🤖 This is an automated message generated by AutoMod (BETA). If you are facing issues, please [contact support](https://support.modrinth.com)."
);
}
str
@@ -146,14 +149,13 @@ impl ModerationMessage {
match self {
ModerationMessage::NoPrimaryFile => "Please attach a file to this version. All files on Modrinth must have files associated with their versions.\n".to_string(),
ModerationMessage::PackFilesNotAllowed { files, .. } => {
let mut str = "".to_string();
str.push_str("This pack redistributes copyrighted material. Please refer to [Modrinth's guide on obtaining modpack permissions](https://support.modrinth.com/en/articles/8797527-obtaining-modpack-permissions) for more information.\n\n");
let mut str = String::from("This pack redistributes copyrighted material. Please refer to [Modrinth's guide on obtaining modpack permissions](https://support.modrinth.com/en/articles/8797527-obtaining-modpack-permissions) for more information.\n\n");
let mut attribute_mods = Vec::new();
let mut no_mods = Vec::new();
let mut permanent_no_mods = Vec::new();
let mut unidentified_mods = Vec::new();
for (_, approval) in files.iter() {
for approval in files.values() {
match approval.status {
ApprovalType::Yes | ApprovalType::WithAttributionAndSource => {}
ApprovalType::WithAttribution => attribute_mods.push(&approval.file_name),
@@ -166,7 +168,7 @@ impl ModerationMessage {
fn print_mods(projects: Vec<&String>, headline: &str, val: &mut String) {
if projects.is_empty() { return }
val.push_str(&format!("{headline}\n\n"));
write!(val, "{headline}\n\n").unwrap();
for project in &projects {
let additional_text = if project.contains("ftb-quests") {
@@ -181,11 +183,11 @@ impl ModerationMessage {
None
};
val.push_str(&if let Some(additional_text) = additional_text {
format!("- {project} (consider using [{}](https://modrinth.com/project/{}) instead)\n", additional_text.0, additional_text.1)
if let Some(additional_text) = additional_text {
writeln!(val, "- {project} (consider using [{}](https://modrinth.com/project/{}) instead)", additional_text.0, additional_text.1).unwrap();
} else {
format!("- {project}\n")
})
writeln!(val, "- {project}").unwrap();
}
}
if !projects.is_empty() {
@@ -278,10 +280,7 @@ impl AutomatedModerationQueue {
let mut zip = ZipArchive::new(reader)?;
let pack: PackFormat = {
let mut file =
if let Ok(file) = zip.by_name("modrinth.index.json") {
file
} else {
let Ok(mut file) = zip.by_name("modrinth.index.json") else {
continue;
};
@@ -301,7 +300,7 @@ impl AutomatedModerationQueue {
.files
.clone()
.into_iter()
.flat_map(|x| {
.filter_map(|x| {
let hash = x.hashes.get(&PackFileHash::Sha1);
if let Some(hash) = hash {
@@ -397,8 +396,8 @@ impl AutomatedModerationQueue {
",
serde_json::to_value(&MissingMetadata {
identified: final_hashes,
flame_files: Default::default(),
unknown_files: Default::default(),
flame_files: HashMap::new(),
unknown_files: HashMap::new(),
})?,
primary_file.id.0
)
@@ -432,8 +431,8 @@ impl AutomatedModerationQueue {
if hashes.is_empty() {
let metadata = MissingMetadata {
identified: final_hashes,
flame_files: Default::default(),
unknown_files: Default::default(),
flame_files: HashMap::new(),
unknown_files: HashMap::new(),
};
sqlx::query!(
@@ -533,8 +532,8 @@ impl AutomatedModerationQueue {
if hashes.is_empty() {
let metadata = MissingMetadata {
identified: final_hashes,
flame_files: Default::default(),
unknown_files: Default::default(),
flame_files: HashMap::new(),
unknown_files: HashMap::new(),
};
sqlx::query!(
@@ -622,8 +621,7 @@ impl AutomatedModerationQueue {
if !mod_messages.is_empty() {
let first_time = database::models::DBThread::get(project.thread_id, &pool).await?
.map(|x| x.messages.iter().all(|x| x.author_id == Some(database::models::DBUserId(AUTOMOD_ID)) || x.hide_identity))
.unwrap_or(true);
.is_none_or(|x| x.messages.iter().all(|x| x.author_id == Some(database::models::DBUserId(AUTOMOD_ID)) || x.hide_identity));
let mut transaction = pool.begin().await?;
let id = ThreadMessageBuilder {
@@ -733,10 +731,12 @@ impl AutomatedModerationQueue {
if let Err(err) = res {
let err = err.as_api_error();
let mut str = String::new();
str.push_str("## Internal AutoMod Error\n\n");
str.push_str(&format!("Error code: {}\n\n", err.error));
str.push_str(&format!("Error description: {}\n\n", err.description));
let str = format!(
"## Internal AutoMod Error\n\n\
Error code: {}\n\n\
Error description: {}\n\n",
err.error, err.description
);
let mut transaction = pool.begin().await?;
ThreadMessageBuilder {

View File

@@ -441,8 +441,8 @@ impl PayoutsQueue {
}
} else {
PayoutMethodFee {
percentage: Default::default(),
min: Default::default(),
percentage: Decimal::default(),
min: Decimal::default(),
max: None,
}
},
@@ -833,7 +833,7 @@ pub async fn process_payout(
.map(|x| (x.project_id, x.page_views))
.collect::<HashMap<u64, u64>>();
for (key, value) in downloads_values.iter() {
for (key, value) in &downloads_values {
let counter = views_values.entry(*key).or_insert(0);
*counter += *value;
}