Fix clippy errors + lint, use turbo CI

This commit is contained in:
Jai A
2024-10-18 16:07:35 -07:00
parent 663ab83b08
commit 8dd955563e
186 changed files with 10615 additions and 6433 deletions

View File

@@ -1,4 +1,6 @@
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;

View File

@@ -1,4 +1,6 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;

View File

@@ -1,4 +1,6 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult,
};
use chrono::DateTime;
use std::io::Cursor;
use zip::ZipArchive;
@@ -16,7 +18,9 @@ impl super::Validator for ForgeValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 1.13, the first forge version which uses the new TOML system
SupportedGameVersions::PastDate(DateTime::from_timestamp(1540122067, 0).unwrap())
SupportedGameVersions::PastDate(
DateTime::from_timestamp(1540122067, 0).unwrap(),
)
}
fn validate(

View File

@@ -1,4 +1,6 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;

View File

@@ -14,7 +14,9 @@ use crate::validate::plugin::*;
use crate::validate::quilt::QuiltValidator;
use crate::validate::resourcepack::{PackValidator, TexturePackValidator};
use crate::validate::rift::RiftValidator;
use crate::validate::shader::{CanvasShaderValidator, CoreShaderValidator, ShaderValidator};
use crate::validate::shader::{
CanvasShaderValidator, CoreShaderValidator, ShaderValidator,
};
use chrono::{DateTime, Utc};
use std::io::Cursor;
use thiserror::Error;
@@ -128,7 +130,8 @@ pub async fn validate_file(
.find_map(|v| MinecraftGameVersion::try_from_version_field(&v).ok())
.unwrap_or_default();
let all_game_versions =
MinecraftGameVersion::list(None, None, &mut *transaction, redis).await?;
MinecraftGameVersion::list(None, None, &mut *transaction, redis)
.await?;
validate_minecraft_file(
data,
@@ -224,23 +227,29 @@ fn game_version_supported(
) -> bool {
match supported_game_versions {
SupportedGameVersions::All => true,
SupportedGameVersions::PastDate(date) => game_versions.iter().any(|x| {
all_game_versions
.iter()
.find(|y| y.version == x.version)
.map(|x| x.created > date)
.unwrap_or(false)
}),
SupportedGameVersions::Range(before, after) => game_versions.iter().any(|x| {
all_game_versions
.iter()
.find(|y| y.version == x.version)
.map(|x| x.created > before && x.created < after)
.unwrap_or(false)
}),
SupportedGameVersions::PastDate(date) => {
game_versions.iter().any(|x| {
all_game_versions
.iter()
.find(|y| y.version == x.version)
.map(|x| x.created > date)
.unwrap_or(false)
})
}
SupportedGameVersions::Range(before, after) => {
game_versions.iter().any(|x| {
all_game_versions
.iter()
.find(|y| y.version == x.version)
.map(|x| x.created > before && x.created < after)
.unwrap_or(false)
})
}
SupportedGameVersions::Custom(versions) => {
let version_ids = versions.iter().map(|gv| gv.id).collect::<Vec<_>>();
let game_version_ids: Vec<_> = game_versions.iter().map(|gv| gv.id).collect::<Vec<_>>();
let version_ids =
versions.iter().map(|gv| gv.id).collect::<Vec<_>>();
let game_version_ids: Vec<_> =
game_versions.iter().map(|gv| gv.id).collect::<Vec<_>>();
version_ids.iter().any(|x| game_version_ids.contains(x))
}
}
@@ -249,7 +258,8 @@ fn game_version_supported(
pub fn filter_out_packs(
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
if (archive.by_name("modlist.html").is_ok() && archive.by_name("manifest.json").is_ok())
if (archive.by_name("modlist.html").is_ok()
&& archive.by_name("manifest.json").is_ok())
|| archive
.file_names()
.any(|x| x.starts_with("mods/") && x.ends_with(".jar"))

View File

@@ -1,6 +1,8 @@
use crate::models::pack::{PackFileHash, PackFormat};
use crate::util::validate::validation_errors_to_string;
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::{Cursor, Read};
use std::path::Component;
use validator::Validate;
@@ -26,11 +28,14 @@ impl super::Validator for ModpackValidator {
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
let pack: PackFormat = {
let mut file = if let Ok(file) = archive.by_name("modrinth.index.json") {
file
} else {
return Ok(ValidationResult::Warning("Pack manifest is missing."));
};
let mut file =
if let Ok(file) = archive.by_name("modrinth.index.json") {
file
} else {
return Ok(ValidationResult::Warning(
"Pack manifest is missing.",
));
};
let mut contents = String::new();
file.read_to_string(&mut contents)?;
@@ -39,7 +44,9 @@ impl super::Validator for ModpackValidator {
};
pack.validate().map_err(|err| {
ValidationError::InvalidInput(validation_errors_to_string(err, None).into())
ValidationError::InvalidInput(
validation_errors_to_string(err, None).into(),
)
})?;
if pack.game != "minecraft" {
@@ -48,8 +55,12 @@ impl super::Validator for ModpackValidator {
));
}
if pack.files.is_empty() && !archive.file_names().any(|x| x.starts_with("overrides/")) {
return Err(ValidationError::InvalidInput("Pack has no files!".into()));
if pack.files.is_empty()
&& !archive.file_names().any(|x| x.starts_with("overrides/"))
{
return Err(ValidationError::InvalidInput(
"Pack has no files!".into(),
));
}
for file in &pack.files {
@@ -68,7 +79,11 @@ impl super::Validator for ModpackValidator {
let path = std::path::Path::new(&file.path)
.components()
.next()
.ok_or_else(|| ValidationError::InvalidInput("Invalid pack file path!".into()))?;
.ok_or_else(|| {
ValidationError::InvalidInput(
"Invalid pack file path!".into(),
)
})?;
match path {
Component::CurDir | Component::Normal(_) => {}

View File

@@ -1,4 +1,6 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;

View File

@@ -1,4 +1,6 @@
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;

View File

@@ -1,4 +1,6 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult,
};
use chrono::DateTime;
use std::io::Cursor;
use zip::ZipArchive;
@@ -15,14 +17,17 @@ impl super::Validator for QuiltValidator {
}
fn get_supported_game_versions(&self) -> SupportedGameVersions {
SupportedGameVersions::PastDate(DateTime::from_timestamp(1646070100, 0).unwrap())
SupportedGameVersions::PastDate(
DateTime::from_timestamp(1646070100, 0).unwrap(),
)
}
fn validate(
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
if archive.by_name("quilt.mod.json").is_err() && archive.by_name("fabric.mod.json").is_err()
if archive.by_name("quilt.mod.json").is_err()
&& archive.by_name("fabric.mod.json").is_err()
{
return Ok(ValidationResult::Warning(
"No quilt.mod.json present for Quilt file.",

View File

@@ -1,4 +1,6 @@
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use chrono::DateTime;
use std::io::Cursor;
use zip::ZipArchive;
@@ -16,7 +18,9 @@ impl super::Validator for PackValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 13w24a which replaced texture packs with resource packs
SupportedGameVersions::PastDate(DateTime::from_timestamp(1371137542, 0).unwrap())
SupportedGameVersions::PastDate(
DateTime::from_timestamp(1371137542, 0).unwrap(),
)
}
fn validate(

View File

@@ -1,4 +1,6 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;

View File

@@ -1,4 +1,6 @@
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use zip::ZipArchive;