Skip to content

Commit 528462d

Browse files
authored
Fix clippy inlined_format_args (#533)
1 parent dc5c15b commit 528462d

28 files changed

+103
-172
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ resource-assembler = []
105105

106106
[lints.clippy]
107107
len_zero = "allow"
108-
# TODO: https://github.com/brave/adblock-rust/issues/501
109-
uninlined_format_args = "allow"
108+
uninlined_format_args = "warn"
110109

111110
[workspace]
112111
members = ["js", "fuzz"]

benches/bench_cosmetic_matching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ fn by_classes_ids(c: &mut Criterion) {
5151

5252
group.bench_function("brave-list", |b| {
5353
for i in 0..1000 {
54-
classes.push(format!("class{}", i));
55-
ids.push(format!("id{}", i));
54+
classes.push(format!("class{i}"));
55+
ids.push(format!("id{i}"));
5656
}
5757

5858
let engine = make_engine();

benches/bench_redirect_performance.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn get_redirect_rules() -> Vec<NetworkFilter> {
7171
.map(|(index, mut rule)| {
7272
rule.mask.insert(NetworkFilterMask::IS_LEFT_ANCHOR);
7373
rule.mask.insert(NetworkFilterMask::IS_RIGHT_ANCHOR);
74-
rule.hostname = Some(format!("a{}.com/bad.js", index));
74+
rule.hostname = Some(format!("a{index}.com/bad.js"));
7575

7676
rule.filter = adblock::filters::network::FilterPart::Empty;
7777
rule.mask.remove(NetworkFilterMask::IS_HOSTNAME_ANCHOR);
@@ -192,7 +192,7 @@ pub fn build_custom_requests(rules: Vec<NetworkFilter>) -> Vec<Request> {
192192
hostname
193193
};
194194

195-
let source_url = format!("https://{}", source_hostname);
195+
let source_url = format!("https://{source_hostname}");
196196

197197
Request::new(&url, &source_url, raw_type).unwrap()
198198
})
@@ -204,9 +204,7 @@ fn bench_fn(engine: &Engine, requests: &[Request]) {
204204
let block_result = engine.check_network_request(request);
205205
assert!(
206206
block_result.redirect.is_some(),
207-
"{:?}, {:?}",
208-
request,
209-
block_result
207+
"{request:?}, {block_result:?}"
210208
);
211209
});
212210
}

examples/deserialization.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn load_requests() -> Vec<RequestRuleMatch> {
2929
if let Ok(record) = result {
3030
reqs.push(record);
3131
} else {
32-
println!("Could not parse {:?}", result);
32+
println!("Could not parse {result:?}");
3333
}
3434
}
3535

@@ -70,7 +70,7 @@ fn main() {
7070
let mut false_negative_exceptions: HashMap<String, (String, String, String)> = HashMap::new();
7171
for (reqs_processed, req) in requests.into_iter().enumerate() {
7272
if reqs_processed % 10000 == 0 {
73-
println!("{} requests processed", reqs_processed);
73+
println!("{reqs_processed} requests processed");
7474
}
7575
let request = Request::new(&req.url, &req.sourceUrl, &req.r#type).unwrap();
7676
let checked = engine.check_network_request(&request);
@@ -106,7 +106,7 @@ fn main() {
106106

107107
let mismatches = mismatch_expected_match + mismatch_expected_exception + mismatch_expected_pass;
108108
let ratio = mismatches as f32 / requests_len as f32;
109-
assert!(ratio < 0.04, "Mismatch ratio was {}", ratio);
109+
assert!(ratio < 0.04, "Mismatch ratio was {ratio}");
110110
assert!(
111111
false_positive_rules.len() < 3,
112112
"False positive rules higher than expected: {:?}",

examples/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ fn main() {
2626
.unwrap();
2727
let blocker_result = engine.check_network_request(&request);
2828

29-
println!("Blocker result: {:?}", blocker_result);
29+
println!("Blocker result: {blocker_result:?}");
3030
}

examples/use-dat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ fn main() {
2525
let checked = engine.check_network_request(&request);
2626
assert!(checked.filter.is_some());
2727
assert!(checked.exception.is_some());
28-
println!("All good: {:?}", checked);
28+
println!("All good: {checked:?}");
2929
}

src/blocker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ impl Blocker {
299299
impl std::fmt::Display for QParam<'_> {
300300
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
301301
match self {
302-
Self::KeyOnly(k) => write!(f, "{}", k),
303-
Self::KeyValue(k, v) => write!(f, "{}={}", k, v),
302+
Self::KeyOnly(k) => write!(f, "{k}"),
303+
Self::KeyValue(k, v) => write!(f, "{k}={v}"),
304304
}
305305
}
306306
}
@@ -354,7 +354,7 @@ impl Blocker {
354354
let new_param_str = if p.is_empty() {
355355
String::from("")
356356
} else {
357-
format!("?{}", p)
357+
format!("?{p}")
358358
};
359359
Some(format!(
360360
"{}{}{}",

src/content_blocking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
377377
let with_fixed_wildcards =
378378
REPLACE_WILDCARDS.replace_all(&escaped_special_chars, ".*");
379379
let mut url_filter = if v.mask.contains(NetworkFilterMask::IS_LEFT_ANCHOR) {
380-
format!("^{}", with_fixed_wildcards)
380+
format!("^{with_fixed_wildcards}")
381381
} else {
382382
let scheme_part = if v
383383
.mask
@@ -394,7 +394,7 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
394394
unreachable!("Invalid scheme information");
395395
};
396396

397-
format!("{}{}", scheme_part, with_fixed_wildcards)
397+
format!("{scheme_part}{with_fixed_wildcards}")
398398
};
399399

400400
if v.mask.contains(NetworkFilterMask::IS_RIGHT_ANCHOR) {
@@ -405,7 +405,7 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
405405
}
406406
(crate::filters::network::FilterPart::Empty, Some(hostname)) => {
407407
let escaped_special_chars = SPECIAL_CHARS.replace_all(&hostname, r##"\$1"##);
408-
format!("^[^:]+:(//)?([^/]+\\.)?{}", escaped_special_chars)
408+
format!("^[^:]+:(//)?([^/]+\\.)?{escaped_special_chars}")
409409
}
410410
(crate::filters::network::FilterPart::Empty, None) => if v
411411
.mask
@@ -464,7 +464,7 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
464464
idna::domain_to_ascii(&lowercase).unwrap()
465465
};
466466

467-
collection.push(format!("*{}", normalized_domain));
467+
collection.push(format!("*{normalized_domain}"));
468468
});
469469

470470
(non_empty(if_domain), non_empty(unless_domain))

src/cosmetic_filter_cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ impl CosmeticFilterCache {
183183

184184
classes.into_iter().for_each(|class| {
185185
let class = class.as_ref();
186-
if simple_class_rules.contains(class) && !exceptions.contains(&format!(".{}", class)) {
187-
selectors.push(format!(".{}", class));
186+
if simple_class_rules.contains(class) && !exceptions.contains(&format!(".{class}")) {
187+
selectors.push(format!(".{class}"));
188188
}
189189
if let Some(values) = complex_class_rules.get(class) {
190190
for sel in values.data() {
@@ -196,8 +196,8 @@ impl CosmeticFilterCache {
196196
});
197197
ids.into_iter().for_each(|id| {
198198
let id = id.as_ref();
199-
if simple_id_rules.contains(id) && !exceptions.contains(&format!("#{}", id)) {
200-
selectors.push(format!("#{}", id));
199+
if simple_id_rules.contains(id) && !exceptions.contains(&format!("#{id}")) {
200+
selectors.push(format!("#{id}"));
201201
}
202202
if let Some(values) = complex_id_rules.get(id) {
203203
for sel in values.data() {

src/filters/cosmetic.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ mod css_validation {
634634

635635
// Use `mock-stylesheet-marker` where uBO uses `color: red` since we have control over the
636636
// parsing logic within the block.
637-
let mock_stylesheet = format!("{}{{mock-stylesheet-marker}}", selector);
637+
let mock_stylesheet = format!("{selector}{{mock-stylesheet-marker}}");
638638
let mut pi = ParserInput::new(&mock_stylesheet);
639639
let mut parser = Parser::new(&mut pi);
640640
let mut parser_impl = QualifiedRuleParserImpl {
@@ -1137,17 +1137,17 @@ mod css_validation {
11371137
fn to_css<W: Write>(&self, dest: &mut W) -> FmtResult {
11381138
write!(dest, ":")?;
11391139
match self {
1140-
Self::HasText(text) => write!(dest, "has-text({})", text)?,
1141-
Self::MatchesAttr(text) => write!(dest, "matches-attr({})", text)?,
1142-
Self::MatchesCss(text) => write!(dest, "matches-css({})", text)?,
1143-
Self::MatchesCssBefore(text) => write!(dest, "matches-css-before({})", text)?,
1144-
Self::MatchesCssAfter(text) => write!(dest, "matches-css-after({})", text)?,
1145-
Self::MatchesPath(text) => write!(dest, "matches-path({})", text)?,
1146-
Self::MinTextLength(text) => write!(dest, "min-text-length({})", text)?,
1147-
Self::Upward(text) => write!(dest, "upward({})", text)?,
1148-
Self::Xpath(text) => write!(dest, "xpath({})", text)?,
1149-
Self::AnythingElse(name, None) => write!(dest, "{}", name)?,
1150-
Self::AnythingElse(name, Some(args)) => write!(dest, "{}({})", name, args)?,
1140+
Self::HasText(text) => write!(dest, "has-text({text})")?,
1141+
Self::MatchesAttr(text) => write!(dest, "matches-attr({text})")?,
1142+
Self::MatchesCss(text) => write!(dest, "matches-css({text})")?,
1143+
Self::MatchesCssBefore(text) => write!(dest, "matches-css-before({text})")?,
1144+
Self::MatchesCssAfter(text) => write!(dest, "matches-css-after({text})")?,
1145+
Self::MatchesPath(text) => write!(dest, "matches-path({text})")?,
1146+
Self::MinTextLength(text) => write!(dest, "min-text-length({text})")?,
1147+
Self::Upward(text) => write!(dest, "upward({text})")?,
1148+
Self::Xpath(text) => write!(dest, "xpath({text})")?,
1149+
Self::AnythingElse(name, None) => write!(dest, "{name}")?,
1150+
Self::AnythingElse(name, Some(args)) => write!(dest, "{name}({args})")?,
11511151
}
11521152
Ok(())
11531153
}
@@ -1198,8 +1198,8 @@ mod css_validation {
11981198
fn to_css<W: Write>(&self, dest: &mut W) -> FmtResult {
11991199
write!(dest, "::")?;
12001200
match self {
1201-
Self(name, None) => write!(dest, "{}", name)?,
1202-
Self(name, Some(args)) => write!(dest, "{}({})", name, args)?,
1201+
Self(name, None) => write!(dest, "{name}")?,
1202+
Self(name, Some(args)) => write!(dest, "{name}({args})")?,
12031203
}
12041204
Ok(())
12051205
}

0 commit comments

Comments
 (0)