From 7f3f4665f8533d64783c5199d8b795fe92410fcb Mon Sep 17 00:00:00 2001 From: Andrew Frantz Date: Thu, 23 Jan 2025 08:21:10 -0500 Subject: [PATCH 1/2] fix: allow urls to be checked Revert "fix: allow urls to be checked" This reverts commit 03abe39e948830ff9b987106dd8cfdb4b2bd8de6. fix: allow urls to be checked --- src/commands/check.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/check.rs b/src/commands/check.rs index ca08fce..8c5dd1a 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -107,8 +107,9 @@ pub async fn check(args: CheckArgs) -> anyhow::Result<()> { ); } if fs::metadata(&file) - .with_context(|| format!("failed to read metadata for file `{file}`"))? - .is_dir() + .with_context(|| format!("failed to read metadata for file `{file}`")) + .map(|m| m.is_dir()) + .unwrap_or_else(|_| false) && args.common.single_document { bail!( From 31e323bbd52f56c60ddc179b8331d2c6a765a48f Mon Sep 17 00:00:00 2001 From: Andrew Frantz Date: Thu, 23 Jan 2025 08:39:29 -0500 Subject: [PATCH 2/2] perf: reorder check to short circuit --- src/commands/check.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/commands/check.rs b/src/commands/check.rs index 8c5dd1a..18e9f51 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -100,17 +100,17 @@ pub async fn check(args: CheckArgs) -> anyhow::Result<()> { let shellcheck = args.common.shellcheck; let file = args.common.file; - if Url::parse(&file).is_ok() && args.common.local_only { + if args.common.local_only && Url::parse(&file).is_ok() { bail!( "`--local-only` was specified, but `{file}` is a remote URL", file = file ); } - if fs::metadata(&file) - .with_context(|| format!("failed to read metadata for file `{file}`")) - .map(|m| m.is_dir()) - .unwrap_or_else(|_| false) - && args.common.single_document + if args.common.single_document + && fs::metadata(&file) + .with_context(|| format!("failed to read metadata for file `{file}`")) + .map(|m| m.is_dir()) + .unwrap_or_else(|_| false) { bail!( "`--single-document` was specified, but `{file}` is a directory",