Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nuke-web3 committed Jun 11, 2024
1 parent b0cb310 commit 8723c38
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
6 changes: 3 additions & 3 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ pub async fn run(config: &Config) -> Result<(), ()> {
}
}


let do_not_warn_for_redirect_to: Arc<Vec<WildMatch>> = 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<Vec<WildMatch>> =
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);
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion src/link_validator/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/link_validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WildMatch>) -> LinkCheckResult {
pub async fn check(
link_target: &str,
link_type: &LinkType,
config: &Config,
do_not_warn_for_redirect_to: &Vec<WildMatch>,
) -> LinkCheckResult {
info!("Check link {}.", &link_target);
match link_type {
LinkType::Ftp => LinkCheckResult::NotImplemented(format!(
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use simplelog::*;
pub enum LogLevel {
Info,
Warn,
Debug
Debug,
}

impl Default for LogLevel {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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);
Expand Down
2 changes: 1 addition & 1 deletion tests/file_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
};
Expand Down
2 changes: 1 addition & 1 deletion tests/throttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8723c38

Please sign in to comment.