Skip to content

Commit 946a110

Browse files
Armin BecherArmin Becher
authored andcommitted
style: fix clippy warnings
1 parent 78727c1 commit 946a110

File tree

9 files changed

+38
-44
lines changed

9 files changed

+38
-44
lines changed

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn parse_args() -> Config {
184184
*p = canonical_path;
185185
}
186186
Err(e) => {
187-
println!("⚠ Warn: Ignore path {:?} not found. {:?}.", p, e);
187+
println!("⚠ Warn: Ignore path {p:?} not found. {e:?}.");
188188
}
189189
};
190190
}
@@ -203,7 +203,7 @@ pub fn parse_args() -> Config {
203203
let root_path =
204204
Path::new(&root_dir.replace(['/', '\\'], std::path::MAIN_SEPARATOR_STR)).to_path_buf();
205205
if !root_path.is_dir() {
206-
eprintln!("Root path {:?} must be a directory!", root_path);
206+
eprintln!("Root path {root_path:?} must be a directory!");
207207
std::process::exit(1);
208208
}
209209
opt.root_dir = Some(root_path)

src/file_traversal.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ pub fn find(config: &Config, result: &mut Vec<MarkupFile>) {
1313
};
1414

1515
info!(
16-
"Search for files of markup types '{:?}' in directory '{:?}'",
17-
markup_types, root
16+
"Search for files of markup types '{markup_types:?}' in directory '{root:?}'"
1817
);
1918

2019
for entry in WalkDir::new(root)
@@ -30,7 +29,7 @@ pub fn find(config: &Config, result: &mut Vec<MarkupFile>) {
3029
.unwrap_or_default()
3130
.starts_with(fs::canonicalize(f).unwrap_or_default());
3231
if ignore {
33-
info!("Ignore directory: '{:?}'", f);
32+
info!("Ignore directory: '{f:?}'");
3433
}
3534
ignore
3635
})
@@ -48,7 +47,7 @@ pub fn find(config: &Config, result: &mut Vec<MarkupFile>) {
4847
let abs_path = match fs::canonicalize(path) {
4948
Ok(abs_path) => abs_path,
5049
Err(e) => {
51-
warn!("Path '{:?}' not able to canonicalize path. '{e}'", path);
50+
warn!("Path '{path:?}' not able to canonicalize path. '{e}'");
5251
continue;
5352
}
5453
};
@@ -64,7 +63,7 @@ pub fn find(config: &Config, result: &mut Vec<MarkupFile>) {
6463
markup_type,
6564
path: path.to_string_lossy().to_string(),
6665
};
67-
debug!("Found file: {:?}.", file);
66+
debug!("Found file: {file:?}.");
6867
result.push(file);
6968
}
7069
}

src/lib.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl fmt::Display for Config {
8989
None => vec![],
9090
};
9191
let markup_types_str: Vec<String> = match &self.optional.markup_types {
92-
Some(p) => p.iter().map(|m| format!["{:?}", m]).collect(),
92+
Some(p) => p.iter().map(|m| format!["{m:?}"]).collect(),
9393
None => vec![],
9494
};
9595
write!(
@@ -206,12 +206,12 @@ fn print_helper(
206206
) {
207207
let mut link_str = format!("[{:^4}] {}", status_code, link.source_str());
208208
if !msg.is_empty() {
209-
link_str += &format!(" - {}", msg);
209+
link_str += &format!(" - {msg}");
210210
}
211211
if error_channel {
212-
eprintln!("{}", link_str);
212+
eprintln!("{link_str}");
213213
} else {
214-
println!("{}", link_str);
214+
println!("{link_str}");
215215
}
216216
}
217217

@@ -247,7 +247,7 @@ pub async fn run(config: &Config) -> Result<(), ()> {
247247

248248
let gitignored_files: Option<Vec<PathBuf>> = if config.optional.gitignore.is_some() {
249249
let files = find_git_ignored_files();
250-
debug!("Found gitignored files: {:?}", files);
250+
debug!("Found gitignored files: {files:?}");
251251
files
252252
} else {
253253
None
@@ -257,7 +257,7 @@ pub async fn run(config: &Config) -> Result<(), ()> {
257257

258258
let gituntracked_files: Option<Vec<PathBuf>> = if config.optional.gituntracked.is_some() {
259259
let files = find_git_untracked_files();
260-
debug!("Found gituntracked files: {:?}", files);
260+
debug!("Found gituntracked files: {files:?}");
261261
files
262262
} else {
263263
None
@@ -344,7 +344,7 @@ pub async fn run(config: &Config) -> Result<(), ()> {
344344
});
345345

346346
let throttle = config.optional.throttle.unwrap_or_default() > 0;
347-
info!("Throttle HTTP requests to same host: {:?}", throttle);
347+
info!("Throttle HTTP requests to same host: {throttle:?}");
348348
let waits = Arc::new(Mutex::new(HashMap::new()));
349349
// See also http://patshaughnessy.net/2020/1/20/downloading-100000-files-using-async-rust
350350
let mut buffered_stream = stream::iter(link_target_groups.keys())
@@ -359,8 +359,7 @@ pub async fn run(config: &Config) -> Result<(), ()> {
359359
return FinalResult {
360360
target: target.clone(),
361361
result_code: LinkCheckResult::Failed(format!(
362-
"Could not parse URL type. Err: {:?}",
363-
error
362+
"Could not parse URL type. Err: {error:?}"
364363
)),
365364
}
366365
}
@@ -480,12 +479,12 @@ pub async fn run(config: &Config) -> Result<(), ()> {
480479
.map(|e| link_target_groups[&e.target].len())
481480
.sum();
482481
let sum = skipped + error_sum + warnings + oks;
483-
println!("Result ({} links):", sum);
482+
println!("Result ({sum} links):");
484483
println!();
485-
println!("OK {}", oks);
486-
println!("Skipped {}", skipped);
487-
println!("Warnings {}", warnings);
488-
println!("Errors {}", error_sum);
484+
println!("OK {oks}");
485+
println!("Skipped {skipped}");
486+
println!("Warnings {warnings}");
487+
println!("Errors {error_sum}");
489488
println!();
490489

491490
// Prepare CSV file if needed

src/link_extractors/link_extractor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn find_links(file: &MarkupFile) -> Vec<Result<MarkupLink, BrokenExtractedLi
6161
let path = &file.path;
6262
let link_extractor = link_extractor_factory(file.markup_type);
6363

64-
info!("Scan file at path '{}' for links.", path);
64+
info!("Scan file at path '{path}' for links.");
6565
match fs::read_to_string(path) {
6666
Ok(text) => {
6767
let mut links = link_extractor.find_links(&text);
@@ -79,8 +79,7 @@ pub fn find_links(file: &MarkupFile) -> Vec<Result<MarkupLink, BrokenExtractedLi
7979
}
8080
Err(e) => {
8181
warn!(
82-
"File '{}'. IO Error: \"{}\". Check your file encoding.",
83-
path, e
82+
"File '{path}'. IO Error: \"{e}\". Check your file encoding."
8483
);
8584
vec![]
8685
}

src/link_extractors/markdown_link_extractor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mod tests {
266266
fn image_reference() {
267267
let le = MarkdownLinkExtractor();
268268
let link_str = "http://example.net/";
269-
let input = format!("\n\nBla ![This is an image link]({})", link_str);
269+
let input = format!("\n\nBla ![This is an image link]({link_str})");
270270
let result = le.find_links(&input);
271271
let expected = Ok(MarkupLink {
272272
target: link_str.to_string(),
@@ -281,7 +281,7 @@ mod tests {
281281
fn link_no_title() {
282282
let le = MarkdownLinkExtractor();
283283
let link_str = "http://example.net/";
284-
let input = format!("[This link]({}) has no title attribute.", link_str);
284+
let input = format!("[This link]({link_str}) has no title attribute.");
285285
let result = le.find_links(&input);
286286
let expected = Ok(MarkupLink {
287287
target: link_str.to_string(),
@@ -296,7 +296,7 @@ mod tests {
296296
fn link_with_title() {
297297
let le = MarkdownLinkExtractor();
298298
let link_str = "http://example.net/";
299-
let input = format!("\n123[This is a link]({} \"with title\") oh yea.", link_str);
299+
let input = format!("\n123[This is a link]({link_str} \"with title\") oh yea.");
300300
let result = le.find_links(&input);
301301
let expected = Ok(MarkupLink {
302302
target: link_str.to_string(),
@@ -388,8 +388,7 @@ mod tests {
388388
let le = MarkdownLinkExtractor();
389389
let link_str = "http://example.net/";
390390
let input = format!(
391-
"This is [an example][arbitrary case-insensitive reference text] reference-style link.\n\n[Arbitrary CASE-insensitive reference text]: {}",
392-
link_str
391+
"This is [an example][arbitrary case-insensitive reference text] reference-style link.\n\n[Arbitrary CASE-insensitive reference text]: {link_str}"
393392
);
394393
let result = le.find_links(&input);
395394
let expected = Ok(MarkupLink {
@@ -406,8 +405,7 @@ mod tests {
406405
let le = MarkdownLinkExtractor();
407406
let link_str = "http://example.net/";
408407
let input = format!(
409-
"Foo Bar\n\n[Arbitrary CASE-insensitive reference text]: {}",
410-
link_str
408+
"Foo Bar\n\n[Arbitrary CASE-insensitive reference text]: {link_str}"
411409
);
412410
let result = le.find_links(&input);
413411
assert_eq!(0, result.len());

src/link_validator/file_system.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use walkdir::WalkDir;
88

99
pub async fn check_filesystem(target: &str, config: &Config) -> LinkCheckResult {
1010
let target = Path::new(target);
11-
debug!("Absolute target path {:?}", target);
11+
debug!("Absolute target path {target:?}");
1212
if target.exists().await {
1313
LinkCheckResult::Ok
1414
} else if !config.optional.match_file_extension.unwrap_or_default()
@@ -26,8 +26,7 @@ pub async fn check_filesystem(target: &str, config: &Config) -> LinkCheckResult
2626
debug!("Check if file ignoring the extension exists.");
2727
if target_parent.exists().await {
2828
debug!(
29-
"Parent {:?} exists. Search dir for file ignoring the extension.",
30-
target_parent
29+
"Parent {target_parent:?} exists. Search dir for file ignoring the extension."
3130
);
3231
for entry in WalkDir::new(target_parent)
3332
.follow_links(false)
@@ -41,7 +40,7 @@ pub async fn check_filesystem(target: &str, config: &Config) -> LinkCheckResult
4140
match file_on_system.file_name() {
4241
Some(file_name) => {
4342
if target_file_name == file_name {
44-
info!("Found file {:?}", file_on_system);
43+
info!("Found file {file_on_system:?}");
4544
return LinkCheckResult::Ok;
4645
}
4746
}
@@ -79,7 +78,7 @@ pub async fn resolve_target_link(source: &str, target: &str, config: &Config) ->
7978
}
8079
}
8180

82-
debug!("Check file system link target {:?}", target);
81+
debug!("Check file system link target {target:?}");
8382
let abs_path = absolute_target_path(source, &fs_link_target)
8483
.await
8584
.to_str()
@@ -95,9 +94,9 @@ pub async fn resolve_target_link(source: &str, target: &str, config: &Config) ->
9594
async fn absolute_target_path(source: &str, target: &PathBuf) -> PathBuf {
9695
let abs_source = canonicalize(source).await.expect("Expected path to exist.");
9796
if target.is_relative() {
98-
let root = format!("{}", MAIN_SEPARATOR);
97+
let root = format!("{MAIN_SEPARATOR}");
9998
let parent = abs_source.parent().unwrap_or_else(|| Path::new(&root));
100-
let new_target = match target.strip_prefix(format!(".{}", MAIN_SEPARATOR)) {
99+
let new_target = match target.strip_prefix(format!(".{MAIN_SEPARATOR}")) {
101100
Ok(t) => t,
102101
Err(_) => target,
103102
};
@@ -127,7 +126,7 @@ mod test {
127126
let path = absolute_target_path(source.to_str().unwrap(), &target).await;
128127

129128
let path_str = path.to_str().unwrap().to_string();
130-
println!("{:?}", path_str);
129+
println!("{path_str:?}");
131130
assert_eq!(path_str.matches('.').count(), 1);
132131
}
133132
}

src/link_validator/http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ pub async fn check_http(
1515
target: &str,
1616
do_not_warn_for_redirect_to: &[WildMatch],
1717
) -> LinkCheckResult {
18-
debug!("Check http link target {:?}", target);
18+
debug!("Check http link target {target:?}");
1919
let url = reqwest::Url::parse(target).expect("URL of unknown type");
2020

2121
match http_request(&url, do_not_warn_for_redirect_to).await {
2222
Ok(response) => response,
23-
Err(error_msg) => LinkCheckResult::Failed(format!("Http(s) request failed. {}", error_msg)),
23+
Err(error_msg) => LinkCheckResult::Failed(format!("Http(s) request failed. {error_msg}")),
2424
}
2525
}
2626

@@ -72,7 +72,7 @@ async fn http_request(
7272
if status.is_success() || status.is_redirection() {
7373
check_redirect(response.url())
7474
} else {
75-
debug!("Got the status code {:?}. Retry with get-request.", status);
75+
debug!("Got the status code {status:?}. Retry with get-request.");
7676
let get_request = Request::new(Method::GET, url.clone());
7777

7878
let response = CLIENT.execute(get_request).await?;

src/link_validator/link_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn get_link_type(link: &str) -> LinkType {
3030

3131
if let Ok(url) = Url::parse(link) {
3232
let scheme = url.scheme();
33-
debug!("Link {} is a URL type with scheme {}", link, scheme);
33+
debug!("Link {link} is a URL type with scheme {scheme}");
3434
return match scheme {
3535
"http" | "https" => LinkType::Http,
3636
"ftp" | "ftps" => LinkType::Ftp,

src/link_validator/mail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::link_validator::LinkCheckResult;
22
use regex::Regex;
33

44
pub fn check_mail(target: &str) -> LinkCheckResult {
5-
debug!("Check mail target {:?}", target);
5+
debug!("Check mail target {target:?}");
66
let mut mail = target;
77
if let Some(stripped) = target.strip_prefix("mailto://") {
88
mail = stripped;

0 commit comments

Comments
 (0)