From 8aa2747df9de3ab6ad48e1306299efd481452546 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 25 Jul 2023 20:24:02 -0700 Subject: [PATCH] cargo clippy --- examples/deserialization.rs | 3 +-- src/blocker.rs | 2 +- src/cosmetic_filter_cache.rs | 2 +- src/engine.rs | 2 +- src/filters/cosmetic.rs | 8 ++++---- src/filters/network.rs | 2 +- src/lists.rs | 2 +- src/optimizer.rs | 2 +- src/resources/scriptlet_resource_storage.rs | 6 +++--- src/utils.rs | 16 ++++++++-------- tests/test_utils.rs | 3 +-- 11 files changed, 23 insertions(+), 25 deletions(-) diff --git a/examples/deserialization.rs b/examples/deserialization.rs index 3988f58d..cf77a47d 100644 --- a/examples/deserialization.rs +++ b/examples/deserialization.rs @@ -26,8 +26,7 @@ fn load_requests() -> Vec { let mut reqs: Vec = Vec::new(); for result in rdr.deserialize() { - if result.is_ok() { - let record: RequestRuleMatch = result.expect("WAT"); + if let Ok(record) = result { reqs.push(record); } else { println!("Could not parse {:?}", result); diff --git a/src/blocker.rs b/src/blocker.rs index fbffaf73..c1130b96 100644 --- a/src/blocker.rs +++ b/src/blocker.rs @@ -428,7 +428,7 @@ impl Blocker { .map(|param| (param, true)) .collect(); - let filters = removeparam_filters.check_all(request, &request_tokens, &NO_TAGS, regex_manager); + let filters = removeparam_filters.check_all(request, request_tokens, &NO_TAGS, regex_manager); let mut rewrite = false; for removeparam_filter in filters { if let Some(removeparam) = &removeparam_filter.modifier_option { diff --git a/src/cosmetic_filter_cache.rs b/src/cosmetic_filter_cache.rs index 208ad48a..8b07e09b 100644 --- a/src/cosmetic_filter_cache.rs +++ b/src/cosmetic_filter_cache.rs @@ -193,7 +193,7 @@ impl CosmeticFilterCache { /// `UrlSpecificResources`. The exceptions, along with the set of already-seen classes and ids, /// must be cached externally as the cosmetic filtering subsystem here is designed to be /// stateless with regard to active page sessions. - pub fn hidden_class_id_selectors<'a>( + pub fn hidden_class_id_selectors( &self, classes: impl IntoIterator>, ids: impl IntoIterator>, diff --git a/src/engine.rs b/src/engine.rs index bf69c345..d08878c5 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -254,7 +254,7 @@ impl Engine { /// corresponding rules are not excepted. /// /// `exceptions` should be passed directly from `UrlSpecificResources`. - pub fn hidden_class_id_selectors<'a>(&self, classes: impl IntoIterator>, ids: impl IntoIterator>, exceptions: &HashSet) -> Vec { + pub fn hidden_class_id_selectors(&self, classes: impl IntoIterator>, ids: impl IntoIterator>, exceptions: &HashSet) -> Vec { self.cosmetic_cache.hidden_class_id_selectors(classes, ids, exceptions) } diff --git a/src/filters/cosmetic.rs b/src/filters/cosmetic.rs index e0e0e7da..96d921bb 100644 --- a/src/filters/cosmetic.rs +++ b/src/filters/cosmetic.rs @@ -52,7 +52,7 @@ pub enum CosmeticFilterAction { impl CosmeticFilterAction { fn new_style(style: &str) -> Result { - if !is_valid_css_style(&style) { + if !is_valid_css_style(style) { return Err(CosmeticFilterError::InvalidCssStyle); } Ok(Self::Style(style.to_string())) @@ -70,7 +70,7 @@ impl CosmeticFilterAction { /// Regex and quoted args aren't supported yet fn forbid_regex_or_quoted_args(arg: &str) -> Result<(), CosmeticFilterError> { - if arg.starts_with("/") || arg.starts_with("\"") || arg.starts_with("\'") { + if arg.starts_with('/') || arg.starts_with('\"') || arg.starts_with('\'') { return Err(CosmeticFilterError::UnsupportedSyntax); } Ok(()) @@ -263,9 +263,9 @@ impl CosmeticFilter { } } } - if after_sharp.ends_with(REMOVE_TOKEN) { + if let Some(before_suffix) = after_sharp.strip_suffix(REMOVE_TOKEN) { action = Some(CosmeticFilterAction::Remove); - selector = &after_sharp[..after_sharp.len() - REMOVE_TOKEN.len()]; + selector = before_suffix; break 'init; } else { action = None; diff --git a/src/filters/network.rs b/src/filters/network.rs index ed0318eb..78f3fd6a 100644 --- a/src/filters/network.rs +++ b/src/filters/network.rs @@ -1356,7 +1356,7 @@ fn check_pattern_left_right_anchor_filter( let request_url = request.get_url(filter.match_case()); match &filter.filter { FilterPart::Empty => true, - FilterPart::Simple(f) => return &request_url == f, + FilterPart::Simple(f) => &request_url == f, FilterPart::AnyOf(filters) => { for f in filters { if &request_url == f { diff --git a/src/lists.rs b/src/lists.rs index 066e41ae..5f9c7bd4 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -465,7 +465,7 @@ pub fn parse_filters( } /// Parse an entire list of filters, ignoring any errors -pub fn parse_filters_with_metadata<'a>( +pub fn parse_filters_with_metadata( list: impl IntoIterator>, debug: bool, opts: ParseOptions, diff --git a/src/optimizer.rs b/src/optimizer.rs index 053bf8ab..04fd7256 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -102,7 +102,7 @@ impl Optimization for SimplePatternGroup { } } - let is_regex = filters.iter().find(|f| f.is_regex()).is_some(); + let is_regex = filters.iter().any(NetworkFilter::is_regex); filter.mask.set(NetworkFilterMask::IS_REGEX, is_regex); let is_complete_regex = filters.iter().any(|f| f.is_complete_regex()); filter diff --git a/src/resources/scriptlet_resource_storage.rs b/src/resources/scriptlet_resource_storage.rs index 24bba43c..7f21492d 100644 --- a/src/resources/scriptlet_resource_storage.rs +++ b/src/resources/scriptlet_resource_storage.rs @@ -134,7 +134,7 @@ pub fn parse_scriptlet_args(args: &str) -> Vec { let args = args.trim_end_matches('\\'); let mut args_vec = vec![]; - if args.trim().len() == 0 { + if args.trim().is_empty() { return args_vec; } @@ -146,13 +146,13 @@ pub fn parse_scriptlet_args(args: &str) -> Vec { let mut part = &args[after_last_delim..comma_pos]; let mut is_continuation = false; - if part.len() > 0 && part.as_bytes()[part.len() - 1] == b'\\' { + if !part.is_empty() && part.as_bytes()[part.len() - 1] == b'\\' { part = &part[0..part.len() - 1]; is_continuation = true; } let mut target = if let Some(s) = continuation.take() { - String::from(s) + s } else { String::new() }; diff --git a/src/utils.rs b/src/utils.rs index dcb44c31..036cd69c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -247,13 +247,13 @@ mod tests { #[test] fn bin_lookup_works() { - assert_eq!(bin_lookup(&vec![], 42), false); - assert_eq!(bin_lookup(&vec![42], 42), true); - assert_eq!(bin_lookup(&vec![1, 2, 3, 4, 42], 42), true); - assert_eq!(bin_lookup(&vec![1, 2, 3, 4, 42], 1), true); - assert_eq!(bin_lookup(&vec![1, 2, 3, 4, 42], 3), true); - assert_eq!(bin_lookup(&vec![1, 2, 3, 4, 42], 43), false); - assert_eq!(bin_lookup(&vec![1, 2, 3, 4, 42], 0), false); - assert_eq!(bin_lookup(&vec![1, 2, 3, 4, 42], 5), false); + assert_eq!(bin_lookup(&[], 42), false); + assert_eq!(bin_lookup(&[42], 42), true); + assert_eq!(bin_lookup(&[1, 2, 3, 4, 42], 42), true); + assert_eq!(bin_lookup(&[1, 2, 3, 4, 42], 1), true); + assert_eq!(bin_lookup(&[1, 2, 3, 4, 42], 3), true); + assert_eq!(bin_lookup(&[1, 2, 3, 4, 42], 43), false); + assert_eq!(bin_lookup(&[1, 2, 3, 4, 42], 0), false); + assert_eq!(bin_lookup(&[1, 2, 3, 4, 42], 5), false); } } diff --git a/tests/test_utils.rs b/tests/test_utils.rs index dad0788d..408aa5dc 100644 --- a/tests/test_utils.rs +++ b/tests/test_utils.rs @@ -13,6 +13,5 @@ pub fn rules_from_lists(lists: impl IntoIterator>) -> impl lists .into_iter() - .map(|filename| read_file_lines(filename.as_ref())) - .flatten() + .flat_map(|filename| read_file_lines(filename.as_ref())) }