diff --git a/lychee-lib/src/checker/file.rs b/lychee-lib/src/checker/file.rs index f972bee09a..d184b3cc08 100644 --- a/lychee-lib/src/checker/file.rs +++ b/lychee-lib/src/checker/file.rs @@ -8,10 +8,8 @@ use crate::{utils::fragment_checker::FragmentChecker, Base, ErrorKind, Status, U /// /// `FileChecker` is responsible for resolving and validating file paths, /// handling both absolute and relative paths. It supports base path resolution, -/// fallback extensions for files without extensions, and optional fragment checking. -/// -/// This creates a `FileChecker` with a base path, fallback extensions for HTML files, -/// and fragment checking enabled. +/// fallback extensions for files without extensions, and optional fragment +/// checking. #[derive(Debug, Clone)] pub(crate) struct FileChecker { /// An optional base path or URL used for resolving relative paths. @@ -25,6 +23,8 @@ pub(crate) struct FileChecker { } impl FileChecker { + /// Create a new `FileChecker` with the given base path, fallback + /// extensions, and fragment checking configuration. pub(crate) fn new( base: Option, fallback_extensions: Vec, @@ -38,8 +38,13 @@ impl FileChecker { } } + /// Check the given file URI for existence and validity. + /// + /// This resolves the URI to a file path, checks if the file exists, and + /// optionally checks for the existence of fragments in HTML files. pub(crate) async fn check(&self, uri: &Uri) -> Status { let Ok(path) = uri.url.to_file_path() else { + // The URI is not a valid file path and cannot be checked. return ErrorKind::InvalidFilePath(uri.clone()).into(); }; @@ -47,13 +52,14 @@ impl FileChecker { self.check_path(&resolved_path, uri).await } + /// Resolve the given path using the base path, if one is set. + /// + /// Base Path fn resolve_path(&self, path: &Path) -> PathBuf { if let Some(Base::Local(base_path)) = &self.base { if path.is_absolute() { let absolute_base_path = if base_path.is_relative() { - std::env::current_dir() - .unwrap_or_else(|_| PathBuf::new()) - .join(base_path) + std::env::current_dir().unwrap_or_default().join(base_path) } else { base_path.clone() }; diff --git a/lychee-lib/src/checker/mail.rs b/lychee-lib/src/checker/mail.rs index 1c3954568a..e7dcef7b8d 100644 --- a/lychee-lib/src/checker/mail.rs +++ b/lychee-lib/src/checker/mail.rs @@ -1,6 +1,11 @@ -use crate::{ErrorKind, Status, Uri}; +#[cfg(all(feature = "email-check", feature = "native-tls"))] use http::StatusCode; +#[cfg(all(feature = "email-check", feature = "native-tls"))] +use crate::ErrorKind; + +use crate::{Status, Uri}; + #[cfg(all(feature = "email-check", feature = "native-tls"))] use check_if_email_exists::{check_email, CheckEmailInput, Reachable}; @@ -26,16 +31,15 @@ impl MailChecker { /// URIs may contain query parameters (e.g. `contact@example.com?subject="Hello"`), /// which are ignored by this check. They are not part of the mail address /// and instead passed to a mail client. + #[cfg(all(feature = "email-check", feature = "native-tls"))] pub(crate) async fn check_mail(&self, uri: &Uri) -> Status { - #[cfg(all(feature = "email-check", feature = "native-tls"))] - { - self.perform_email_check(uri).await - } + self.perform_email_check(uri).await + } - #[cfg(not(all(feature = "email-check", feature = "native-tls")))] - { - Status::Excluded - } + /// Ignore the mail check if the `email-check` and `native-tls` features are not enabled. + #[cfg(not(all(feature = "email-check", feature = "native-tls")))] + pub(crate) async fn check_mail(&self, _uri: &Uri) -> Status { + Status::Excluded } #[cfg(all(feature = "email-check", feature = "native-tls"))]