Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Jul 26, 2023
1 parent dffd9e2 commit 8aa2747
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 25 deletions.
3 changes: 1 addition & 2 deletions examples/deserialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ fn load_requests() -> Vec<RequestRuleMatch> {

let mut reqs: Vec<RequestRuleMatch> = 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);
Expand Down
2 changes: 1 addition & 1 deletion src/blocker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/cosmetic_filter_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item=impl AsRef<str>>,
ids: impl IntoIterator<Item=impl AsRef<str>>,
Expand Down
2 changes: 1 addition & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item=impl AsRef<str>>, ids: impl IntoIterator<Item=impl AsRef<str>>, exceptions: &HashSet<String>) -> Vec<String> {
pub fn hidden_class_id_selectors(&self, classes: impl IntoIterator<Item=impl AsRef<str>>, ids: impl IntoIterator<Item=impl AsRef<str>>, exceptions: &HashSet<String>) -> Vec<String> {
self.cosmetic_cache.hidden_class_id_selectors(classes, ids, exceptions)
}

Expand Down
8 changes: 4 additions & 4 deletions src/filters/cosmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum CosmeticFilterAction {

impl CosmeticFilterAction {
fn new_style(style: &str) -> Result<Self, CosmeticFilterError> {
if !is_valid_css_style(&style) {
if !is_valid_css_style(style) {
return Err(CosmeticFilterError::InvalidCssStyle);
}
Ok(Self::Style(style.to_string()))
Expand All @@ -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(())
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/filters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item=impl AsRef<str>>,
debug: bool,
opts: ParseOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/resources/scriptlet_resource_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn parse_scriptlet_args(args: &str) -> Vec<String> {
let args = args.trim_end_matches('\\');

let mut args_vec = vec![];
if args.trim().len() == 0 {
if args.trim().is_empty() {
return args_vec;
}

Expand All @@ -146,13 +146,13 @@ pub fn parse_scriptlet_args(args: &str) -> Vec<String> {
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()
};
Expand Down
16 changes: 8 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ pub fn rules_from_lists(lists: impl IntoIterator<Item=impl AsRef<str>>) -> impl

lists
.into_iter()
.map(|filename| read_file_lines(filename.as_ref()))
.flatten()
.flat_map(|filename| read_file_lines(filename.as_ref()))
}

0 comments on commit 8aa2747

Please sign in to comment.