From de5a5f103fbc65cfdfecfeffb14d2e559f27627f Mon Sep 17 00:00:00 2001 From: joshmc Date: Sat, 14 Nov 2020 09:18:43 +0000 Subject: [PATCH] ISSUE-16 - Making PR requested changes: * Updating usages of `krates::Builder` to KratesBuilder * Removing commented out code * Making requested changes from a later version of clippy Signed-off-by: joshmc --- cargo-geiger/src/args.rs | 2 +- cargo-geiger/src/cli.rs | 6 ++++-- cargo-geiger/src/format/display.rs | 4 ++-- cargo-geiger/src/format/print_config.rs | 26 ++++++++++++++++--------- cargo-geiger/src/graph.rs | 2 ++ cargo-geiger/src/scan/default.rs | 9 +++++---- cargo-geiger/src/scan/forbid/table.rs | 6 ------ cargo-geiger/src/utils/core.rs | 5 +++-- cargo-geiger/src/utils/krates.rs | 4 ++-- cargo-geiger/src/utils/metadata.rs | 4 ++-- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/cargo-geiger/src/args.rs b/cargo-geiger/src/args.rs index c9776fb1..b36752d0 100644 --- a/cargo-geiger/src/args.rs +++ b/cargo-geiger/src/args.rs @@ -173,7 +173,7 @@ fn parse_features(raw_features: Option) -> Vec { .unwrap_or_else(String::new) .split(' ') .map(str::to_owned) - .filter(|f| f != "") + .filter(|f| !f.is_empty()) .collect::>() } diff --git a/cargo-geiger/src/cli.rs b/cargo-geiger/src/cli.rs index 089bc7df..b1d855fa 100644 --- a/cargo-geiger/src/cli.rs +++ b/cargo-geiger/src/cli.rs @@ -22,7 +22,8 @@ use cargo::util::{self, important_paths, CargoResult}; use cargo::Config; use cargo_metadata::{CargoOpt, Metadata, MetadataCommand}; use cargo_platform::Cfg; -use krates::{Builder, Krates}; +use krates::Builder as KratesBuilder; +use krates::Krates; use std::path::PathBuf; use std::str::{self, FromStr}; @@ -83,7 +84,8 @@ pub fn get_cfgs( } pub fn get_krates(cargo_metadata: &Metadata) -> CargoResult { - Ok(Builder::new().build_with_metadata(cargo_metadata.clone(), |_| ())?) + Ok(KratesBuilder::new() + .build_with_metadata(cargo_metadata.clone(), |_| ())?) } pub fn get_registry<'a>( diff --git a/cargo-geiger/src/format/display.rs b/cargo-geiger/src/format/display.rs index 83e8ae00..e2bd7fed 100644 --- a/cargo-geiger/src/format/display.rs +++ b/cargo-geiger/src/format/display.rs @@ -61,7 +61,7 @@ pub mod display_tests { use cargo::core::manifest::ManifestMetadata; use cargo_metadata::{CargoOpt, MetadataCommand}; - use krates::Builder; + use krates::Builder as KratesBuilder; use rstest::*; #[rstest( @@ -94,7 +94,7 @@ pub mod display_tests { .exec() .unwrap(); - let krates = Builder::new() + let krates = KratesBuilder::new() .build_with_metadata(metadata.clone(), |_| ()) .unwrap(); diff --git a/cargo-geiger/src/format/print_config.rs b/cargo-geiger/src/format/print_config.rs index 2cac9fa7..32f6863c 100644 --- a/cargo-geiger/src/format/print_config.rs +++ b/cargo-geiger/src/format/print_config.rs @@ -122,8 +122,10 @@ mod print_config_tests { input_invert_bool: bool, expected_edge_direction: EdgeDirection, ) { - let mut args = Args::default(); - args.invert = input_invert_bool; + let args = Args { + invert: input_invert_bool, + .. Default::default() + }; let print_config_result = PrintConfig::new(&args); @@ -144,8 +146,10 @@ mod print_config_tests { input_include_tests_bool: bool, expected_include_tests: IncludeTests, ) { - let mut args = Args::default(); - args.include_tests = input_include_tests_bool; + let args = Args { + include_tests: input_include_tests_bool, + .. Default::default() + }; let print_config_result = PrintConfig::new(&args); @@ -170,9 +174,11 @@ mod print_config_tests { input_no_indent_bool: bool, expected_output_prefix: Prefix, ) { - let mut args = Args::default(); - args.prefix_depth = input_prefix_depth_bool; - args.no_indent = input_no_indent_bool; + let args = Args { + no_indent: input_no_indent_bool, + prefix_depth: input_prefix_depth_bool, + .. Default::default() + }; let print_config_result = PrintConfig::new(&args); @@ -191,8 +197,10 @@ mod print_config_tests { input_verbosity_u32: u32, expected_verbosity: Verbosity, ) { - let mut args = Args::default(); - args.verbose = input_verbosity_u32; + let args = Args { + verbose: input_verbosity_u32, + .. Default::default() + }; let print_config_result = PrintConfig::new(&args); diff --git a/cargo-geiger/src/graph.rs b/cargo-geiger/src/graph.rs index 95cf3076..1f4fadf7 100644 --- a/cargo-geiger/src/graph.rs +++ b/cargo-geiger/src/graph.rs @@ -26,6 +26,8 @@ pub enum ExtraDeps { } impl ExtraDeps { + // This clippy recommendation is valid, but makes this function much harder to read + #[allow(clippy::match_like_matches_macro)] pub fn allows(&self, dep: DependencyKind) -> bool { match (self, dep) { (_, DependencyKind::Normal) => true, diff --git a/cargo-geiger/src/scan/default.rs b/cargo-geiger/src/scan/default.rs index 94a13154..d898acc2 100644 --- a/cargo-geiger/src/scan/default.rs +++ b/cargo-geiger/src/scan/default.rs @@ -188,10 +188,11 @@ mod default_tests { input_features: Vec, expected_compile_features: Vec<&str>, ) { - let mut args = FeaturesArgs::default(); - args.all_features = rand::random(); - args.features = input_features; - args.no_default_features = rand::random(); + let args = FeaturesArgs{ + all_features: rand::random(), + features: input_features, + no_default_features: rand::random() + }; let config = Config::default().unwrap(); let compile_options = build_compile_options(&args, &config); diff --git a/cargo-geiger/src/scan/forbid/table.rs b/cargo-geiger/src/scan/forbid/table.rs index 7780dc0a..1e1f59cb 100644 --- a/cargo-geiger/src/scan/forbid/table.rs +++ b/cargo-geiger/src/scan/forbid/table.rs @@ -144,12 +144,6 @@ fn handle_package_text_tree_line( let sym_lock = emoji_symbols.emoji(SymbolKind::Lock); let sym_qmark = emoji_symbols.emoji(SymbolKind::QuestionMark); - /*let package = package_set - .get_one( - package_id - .to_package_id(cargo_metadata_parameters.krates, package_set), - ) - .unwrap(); // FIXME*/ let name = format_package_name( cargo_metadata_parameters, &package_id, diff --git a/cargo-geiger/src/utils/core.rs b/cargo-geiger/src/utils/core.rs index 8c4139d5..4c10255a 100644 --- a/cargo-geiger/src/utils/core.rs +++ b/cargo-geiger/src/utils/core.rs @@ -66,7 +66,8 @@ mod core_tests { use cargo::Config; use cargo_metadata::{CargoOpt, Metadata, MetadataCommand}; - use krates::{Builder, Krates}; + use krates::Builder as KratesBuilder; + use krates::Krates; use rstest::*; use std::path::PathBuf; @@ -130,7 +131,7 @@ mod core_tests { .exec() .unwrap(); - let krates = Builder::new() + let krates = KratesBuilder::new() .build_with_metadata(metadata.clone(), |_| ()) .unwrap(); diff --git a/cargo-geiger/src/utils/krates.rs b/cargo-geiger/src/utils/krates.rs index 194d1784..13cf99db 100644 --- a/cargo-geiger/src/utils/krates.rs +++ b/cargo-geiger/src/utils/krates.rs @@ -44,7 +44,7 @@ mod krates_tests { use super::*; use cargo_metadata::{CargoOpt, Metadata, MetadataCommand}; - use krates::Builder; + use krates::Builder as KratesBuilder; use rstest::*; #[rstest] @@ -72,7 +72,7 @@ mod krates_tests { .exec() .unwrap(); - let krates = Builder::new() + let krates = KratesBuilder::new() .build_with_metadata(metadata.clone(), |_| ()) .unwrap(); diff --git a/cargo-geiger/src/utils/metadata.rs b/cargo-geiger/src/utils/metadata.rs index 458b1c90..308fc914 100644 --- a/cargo-geiger/src/utils/metadata.rs +++ b/cargo-geiger/src/utils/metadata.rs @@ -140,7 +140,7 @@ mod metadata_tests { use cargo::Config; use cargo_metadata::{CargoOpt, Metadata, MetadataCommand}; - use krates::Builder; + use krates::Builder as KratesBuilder; use rstest::*; use std::path::PathBuf; @@ -305,7 +305,7 @@ mod metadata_tests { .exec() .unwrap(); - let krates = Builder::new() + let krates = KratesBuilder::new() .build_with_metadata(metadata.clone(), |_| ()) .unwrap();