From b3248bc280b2266badafd8a214f105d1af7e8b05 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Sun, 14 Aug 2022 15:04:55 +0200 Subject: [PATCH] add embarks standard lints --- .cargo/config.toml | 79 ++++++++++++++++++++++++++++++++++++++++++++ src/collector/mod.rs | 11 +++--- src/config/mod.rs | 8 ++--- 3 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..3d31fa7 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,79 @@ +[target.'cfg(all())'] +rustflags = [ + # BEGIN - Embark standard lints v6 for Rust 1.55+ + # do not change or add/remove here, but one can add exceptions after this section + # for more info see: + "-Dunsafe_code", + "-Wclippy::all", + "-Wclippy::await_holding_lock", + "-Wclippy::char_lit_as_u8", + "-Wclippy::checked_conversions", + "-Wclippy::dbg_macro", + "-Wclippy::debug_assert_with_mut_call", + "-Wclippy::doc_markdown", + "-Wclippy::empty_enum", + "-Wclippy::enum_glob_use", + "-Wclippy::exit", + "-Wclippy::expl_impl_clone_on_copy", + "-Wclippy::explicit_deref_methods", + "-Wclippy::explicit_into_iter_loop", + "-Wclippy::fallible_impl_from", + "-Wclippy::filter_map_next", + "-Wclippy::flat_map_option", + "-Wclippy::float_cmp_const", + "-Wclippy::fn_params_excessive_bools", + "-Wclippy::from_iter_instead_of_collect", + "-Wclippy::if_let_mutex", + "-Wclippy::implicit_clone", + "-Wclippy::imprecise_flops", + "-Wclippy::inefficient_to_string", + "-Wclippy::invalid_upcast_comparisons", + "-Wclippy::large_digit_groups", + "-Wclippy::large_stack_arrays", + "-Wclippy::large_types_passed_by_value", + "-Wclippy::let_unit_value", + "-Wclippy::linkedlist", + "-Wclippy::lossy_float_literal", + "-Wclippy::macro_use_imports", + "-Wclippy::manual_ok_or", + "-Wclippy::map_err_ignore", + "-Wclippy::map_flatten", + "-Wclippy::map_unwrap_or", + "-Wclippy::match_on_vec_items", + "-Wclippy::match_same_arms", + "-Wclippy::match_wild_err_arm", + "-Wclippy::match_wildcard_for_single_variants", + "-Wclippy::mem_forget", + "-Wclippy::mismatched_target_os", + "-Wclippy::missing_enforced_import_renames", + "-Wclippy::mut_mut", + "-Wclippy::mutex_integer", + "-Wclippy::needless_borrow", + "-Wclippy::needless_continue", + "-Wclippy::needless_for_each", + "-Wclippy::option_option", + "-Wclippy::path_buf_push_overwrite", + "-Wclippy::ptr_as_ptr", + "-Wclippy::rc_mutex", + "-Wclippy::ref_option_ref", + "-Wclippy::rest_pat_in_fully_bound_structs", + "-Wclippy::same_functions_in_if_condition", + "-Wclippy::semicolon_if_nothing_returned", + "-Wclippy::single_match_else", + "-Wclippy::string_add_assign", + "-Wclippy::string_add", + "-Wclippy::string_lit_as_bytes", + "-Wclippy::string_to_string", + "-Wclippy::todo", + "-Wclippy::trait_duplication_in_bounds", + "-Wclippy::unimplemented", + "-Wclippy::unnested_or_patterns", + "-Wclippy::unused_self", + "-Wclippy::useless_transmute", + "-Wclippy::verbose_file_reads", + "-Wclippy::zero_sized_map_values", + "-Wfuture_incompatible", + "-Wnonstandard_style", + "-Wrust_2018_idioms", + # END - Embark standard lints v6 for Rust 1.55+ +] diff --git a/src/collector/mod.rs b/src/collector/mod.rs index 11b7043..82d2321 100644 --- a/src/collector/mod.rs +++ b/src/collector/mod.rs @@ -58,19 +58,19 @@ impl MetricBuilder { } } pub fn value(&mut self, v: f64) { - self.value = Some(v) + self.value = Some(v); } pub fn targets(&mut self, t: Vec) { - self.targets.extend(t.into_iter()) + self.targets.extend(t.into_iter()); } pub fn parser(&mut self, p: Box) { - self.parser = Some(p) + self.parser = Some(p); } pub fn pipeline_stages( &mut self, ps: Vec>, ) { - self.pipeline_stages.extend(ps.into_iter()) + self.pipeline_stages.extend(ps.into_iter()); } pub fn build(self) -> Metric { @@ -118,8 +118,7 @@ impl Metric { labels.sort(); let value = match (parsed.value, self.value) { - (Some(value), _) => Ok(value), - (_, Some(value)) => Ok(value), + (Some(value), _) | (_, Some(value)) => Ok(value), (None, None) => Err(CollectError::MissingValue(String::from( "expected either a constant or a parsed value", ))), diff --git a/src/config/mod.rs b/src/config/mod.rs index ff93114..e55226f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -64,12 +64,12 @@ pub fn parse(path: String) -> serde_yaml::Result { pattern, } => Box::new(crate::parsers::regex::RegexParser::new( pattern, - labels.to_vec(), - value.to_owned(), + labels.clone(), + value.clone(), )), Parser::Json { labels, value } => Box::new(crate::parsers::json::JsonParser::new( - labels.to_vec(), - value.to_owned(), + labels.clone(), + value.clone(), )), };