From e518ff703f56bd0ef78c869e189739415b9ea750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuke=20=F0=9F=8C=84?= Date: Sun, 23 Jun 2024 14:23:06 -0600 Subject: [PATCH] chore: cargo fmt (#93) --- benches/benchmarks.rs | 6 +++--- src/lib.rs | 19 ++++++++++++------- src/link_validator/file_system.rs | 4 +++- src/link_validator/mod.rs | 11 +++++++---- src/logger.rs | 2 +- src/main.rs | 2 +- tests/file_traversal.rs | 2 +- tests/throttle.rs | 2 +- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index bac3b9a..4629474 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -10,10 +10,10 @@ use std::fs; fn end_to_end_benchmark() { let config = Config { directory: fs::canonicalize("./benches/benchmark/markdown/ignore_me_dir").unwrap(), - optional: OptionalConfig { - markup_types: Some(vec![MarkupType::Markdown]), + optional: OptionalConfig { + markup_types: Some(vec![MarkupType::Markdown]), ..Default::default() - }, + }, }; let _ = mlc::run(&config); } diff --git a/src/lib.rs b/src/lib.rs index 2353d3b..479faaf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,11 +190,11 @@ pub async fn run(config: &Config) -> Result<(), ()> { } } - - let do_not_warn_for_redirect_to: Arc> = Arc::new(match &config.optional.do_not_warn_for_redirect_to { - Some(s) => s.iter().map(|m| WildMatch::new(m)).collect(), - None => vec![], - }); + let do_not_warn_for_redirect_to: Arc> = + Arc::new(match &config.optional.do_not_warn_for_redirect_to { + Some(s) => s.iter().map(|m| WildMatch::new(m)).collect(), + None => vec![], + }); let throttle = config.optional.throttle.unwrap_or_default() > 0; info!("Throttle HTTP requests to same host: {:?}", throttle); @@ -254,8 +254,13 @@ pub async fn run(config: &Config) -> Result<(), ()> { } } - let result_code = - link_validator::check(&target.target, &target.link_type, config, &do_not_warn_for_redirect_to).await; + let result_code = link_validator::check( + &target.target, + &target.link_type, + config, + &do_not_warn_for_redirect_to, + ) + .await; FinalResult { target: target.clone(), diff --git a/src/link_validator/file_system.rs b/src/link_validator/file_system.rs index e6e0ba7..4185a23 100644 --- a/src/link_validator/file_system.rs +++ b/src/link_validator/file_system.rs @@ -11,7 +11,9 @@ pub async fn check_filesystem(target: &str, config: &Config) -> LinkCheckResult debug!("Absolute target path {:?}", target); if target.exists().await { LinkCheckResult::Ok - } else if !config.optional.match_file_extension.unwrap_or_default() && target.extension().is_none() { + } else if !config.optional.match_file_extension.unwrap_or_default() + && target.extension().is_none() + { // Check if file exists ignoring the file extension let target_file_name = match target.file_name() { Some(s) => s, diff --git a/src/link_validator/mod.rs b/src/link_validator/mod.rs index a9091cc..af54da1 100644 --- a/src/link_validator/mod.rs +++ b/src/link_validator/mod.rs @@ -35,7 +35,12 @@ pub async fn resolve_target_link( } } -pub async fn check(link_target: &str, link_type: &LinkType, config: &Config, do_not_warn_for_redirect_to: &Vec) -> LinkCheckResult { +pub async fn check( + link_target: &str, + link_type: &LinkType, + config: &Config, + do_not_warn_for_redirect_to: &Vec, +) -> LinkCheckResult { info!("Check link {}.", &link_target); match link_type { LinkType::Ftp => LinkCheckResult::NotImplemented(format!( @@ -48,9 +53,7 @@ pub async fn check(link_target: &str, link_type: &LinkType, config: &Config, do_ LinkType::Mail => check_mail(link_target), LinkType::Http => { if config.optional.offline.unwrap_or_default() { - LinkCheckResult::Ignored( - "Ignore web link because of the offline flag.".to_string(), - ) + LinkCheckResult::Ignored("Ignore web link because of the offline flag.".to_string()) } else { check_http(link_target, do_not_warn_for_redirect_to).await } diff --git a/src/logger.rs b/src/logger.rs index aacb4be..50abc7d 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -7,7 +7,7 @@ use simplelog::*; pub enum LogLevel { Info, Warn, - Debug + Debug, } impl Default for LogLevel { diff --git a/src/main.rs b/src/main.rs index 6bad157..dd1f538 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ async fn main() -> Result<(), Box> { let config = cli::parse_args(); let log_level = match config.optional.debug { Some(true) => logger::LogLevel::Debug, - _ => logger::LogLevel::Warn, + _ => logger::LogLevel::Warn, }; logger::init(&log_level); info!("Config: {}", &config); diff --git a/tests/file_traversal.rs b/tests/file_traversal.rs index 061cc14..0f2ce90 100644 --- a/tests/file_traversal.rs +++ b/tests/file_traversal.rs @@ -27,7 +27,7 @@ fn empty_folder() { let config: Config = Config { directory: path, optional: OptionalConfig { - markup_types: Some(vec![MarkupType::Markdown]), + markup_types: Some(vec![MarkupType::Markdown]), ..Default::default() }, }; diff --git a/tests/throttle.rs b/tests/throttle.rs index 9ca7db0..5853f47 100644 --- a/tests/throttle.rs +++ b/tests/throttle.rs @@ -2,7 +2,7 @@ mod helper; use helper::benches_dir; -use mlc::{Config, OptionalConfig, markup::MarkupType}; +use mlc::{markup::MarkupType, Config, OptionalConfig}; use std::time::{Duration, Instant}; const TEST_THROTTLE_MS: u32 = 100;