From 13324700ba292b7d18d8730d785ef30252a3d6cd Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Mon, 4 Apr 2022 11:44:19 +0300 Subject: [PATCH] Post-cleaning --- common/src/bin/asset_migrate.rs | 19 +++++++++---------- common/src/comp/inventory/loadout_builder.rs | 9 +++------ common/src/generation.rs | 4 +++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/common/src/bin/asset_migrate.rs b/common/src/bin/asset_migrate.rs index 7ffc2c53cc..c3635198aa 100644 --- a/common/src/bin/asset_migrate.rs +++ b/common/src/bin/asset_migrate.rs @@ -276,6 +276,7 @@ mod entity_v2 { pub type Config = EntityConfig; #[derive(Debug, Deserialize, Serialize, Clone)] + #[allow(clippy::large_enum_variant)] pub enum LoadoutKindNew { FromBody, Asset(String), @@ -363,7 +364,7 @@ mod entity_v2 { Self { loadout: LoadoutKindNew::Inline(LoadoutSpecNew { inherit: loadout.map(|asset| match asset { - LoadoutAsset::Loadout(s) => Base::Asset(s.to_owned()), + LoadoutAsset::Loadout(s) => Base::Asset(s), LoadoutAsset::Choice(bases) => Base::Choice( bases .iter() @@ -408,11 +409,11 @@ mod entity_v2 { } mod old { - pub type Config = super::loadout_v1::Config; + pub type Config = super::entity_v1::Config; } mod new { - pub type Config = super::loadout_v2::Config; + pub type Config = super::entity_v2::Config; } #[derive(Debug)] @@ -465,12 +466,10 @@ where // Grab all comments from old file let source = fs::File::open(from.join(&path))?; let mut comments = Vec::new(); - for line in BufReader::new(source).lines() { - if let Ok(line) = line { - if let Some(idx) = line.find("//") { - let comment = &line[idx..line.len()]; - comments.push(comment.to_owned()); - } + for line in BufReader::new(source).lines().flatten() { + if let Some(idx) = line.find("//") { + let comment = &line[idx..line.len()]; + comments.push(comment.to_owned()); } } // Parse the file @@ -488,7 +487,7 @@ where } else { let mut comments = comments.join("\n"); // insert newline for other config content - comments.push_str("\n"); + comments.push('\n'); comments }; diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 82e7ca1330..9885b5de8b 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -1,4 +1,4 @@ -#![warn(clippy::pedantic)] +//#![warn(clippy::pedantic)] //#![warn(clippy::nursery)] use crate::{ assets::{self, AssetExt}, @@ -37,13 +37,13 @@ pub enum ValidationError { } // TODO: serde un-tag? +// // // Pros: // + less noise // // Cons: // - limits us to using different types for each variant -// - doesn't work with some serde feature I don't remember #[derive(Debug, Deserialize, Clone)] enum ItemSpec { Item(String), @@ -196,6 +196,7 @@ impl Base { // TODO: remove clone #[derive(Debug, Deserialize, Clone, Default)] +#[serde(deny_unknown_fields)] pub struct LoadoutSpec { // Meta fields inherit: Option, @@ -754,7 +755,6 @@ impl LoadoutBuilder { Self::from_asset(asset_specifier, rng).expect("failed to load loadut config") } - #[must_use] /// Construct new `LoadoutBuilder` from `asset_specifier` pub fn from_asset(asset_specifier: &str, rng: &mut impl Rng) -> Result { let loadout = Self::empty(); @@ -773,7 +773,6 @@ impl LoadoutBuilder { .with_default_equipment(body) } - #[must_use] /// Construct new `LoadoutBuilder` from `asset_specifier` pub fn from_loadout_spec( loadout_spec: LoadoutSpec, @@ -1173,7 +1172,6 @@ mod tests { // // Things that will be catched - invalid assets paths #[test] - #[ignore = "UNIGNORE BEFORE MERGE!!!"] fn test_loadout_presets() { for preset in Preset::iter() { std::mem::drop(LoadoutBuilder::empty().with_preset(preset)); @@ -1187,7 +1185,6 @@ mod tests { // we will check some loadout assets at least two times. // One for asset itself and second if it serves as a base for other asset. #[test] - #[ignore = "UNIGNORE BEFORE MERGE!!!"] fn validate_all_loadout_assets() { let loadouts = assets::load_dir::("common.loadout", true) .expect("failed to load loadout directory"); diff --git a/common/src/generation.rs b/common/src/generation.rs index 35e013c833..8d71ed6bb7 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -38,6 +38,7 @@ impl Default for AlignmentMark { } #[derive(Debug, Deserialize, Clone)] +#[allow(clippy::large_enum_variant)] pub enum LoadoutKind { FromBody, Asset(String), @@ -90,6 +91,7 @@ pub enum Meta { /// EntityInfo::at(dummy_position).with_asset_expect("common.entity.template", &mut dummy_rng); /// ``` #[derive(Debug, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct EntityConfig { /// Name of Entity /// Can be Name(String) with given name @@ -518,7 +520,7 @@ mod tests { let loadout = LoadoutSpec::load_cloned(&asset).expect("failed to load loadout asset"); loadout - .validate(vec![asset.to_owned()]) + .validate(vec![asset]) .unwrap_or_else(|e| panic!("Config {config_asset} is broken: {e:?}")); }, LoadoutKind::Inline(spec) => {