Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed Oct 17, 2024
1 parent 66470c7 commit be20046
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
20 changes: 13 additions & 7 deletions lychee-lib/src/checker/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Base>,
fallback_extensions: Vec<String>,
Expand All @@ -38,22 +38,28 @@ 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();
};

let resolved_path = self.resolve_path(&path);
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()
};
Expand Down
22 changes: 13 additions & 9 deletions lychee-lib/src/checker/mail.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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"))]
Expand Down

0 comments on commit be20046

Please sign in to comment.