diff --git a/README.md b/README.md index 59cb844..dc06536 100644 --- a/README.md +++ b/README.md @@ -424,13 +424,13 @@ Options: URLs to check (supports regex). Has preference over all excludes --exclude - Exclude URLs and mail addresses from checking (supports regex) + Exclude URLs and mail addresses from checking. The values are treated as regular expressions --exclude-file Deprecated; use `--exclude-path` instead --exclude-path - Exclude file path from getting checked + Exclude paths from getting checked. The values are treated as regular expressions -E, --exclude-all-private Exclude all private IPs from checking. diff --git a/fixtures/configs/smoketest.toml b/fixtures/configs/smoketest.toml index 6ae6a33..1e88747 100644 --- a/fixtures/configs/smoketest.toml +++ b/fixtures/configs/smoketest.toml @@ -99,10 +99,10 @@ include_verbatim = false # Ignore case of paths when matching glob patterns. glob_ignore_case = false -# Exclude URLs and mail addresses from checking (supports regex). +# Exclude URLs and mail addresses from checking. The values are treated as regular expressions exclude = ['.*\.github.com\.*'] -# Exclude these filesystem paths from getting checked. +# Exclude paths from getting checked. The values are treated as regular expressions exclude_path = ["file/path/to/Ignore", "./other/file/path/to/Ignore"] # URLs to check (supports regex). Has preference over all excludes. diff --git a/lychee-bin/src/options.rs b/lychee-bin/src/options.rs index 64fd772..c2f80ba 100644 --- a/lychee-bin/src/options.rs +++ b/lychee-bin/src/options.rs @@ -505,7 +505,7 @@ and 501." pub(crate) include: Vec, /// Exclude URLs and mail addresses from checking. - /// The value is treated as regular expression. + /// The values are treated as regular expressions. #[arg(long)] #[serde(default)] pub(crate) exclude: Vec, @@ -516,7 +516,7 @@ and 501." pub(crate) exclude_file: Vec, /// Exclude paths from getting checked. - /// The value is treated as regular expression. + /// The values are treated as regular expressions. #[arg(long)] #[serde(default)] pub(crate) exclude_path: Vec, diff --git a/lychee-lib/src/types/input.rs b/lychee-lib/src/types/input.rs index 8631c75..adc454e 100644 --- a/lychee-lib/src/types/input.rs +++ b/lychee-lib/src/types/input.rs @@ -2,7 +2,7 @@ use super::file::FileExtensions; use super::resolver::UrlContentResolver; use crate::filter::PathExcludes; use crate::types::FileType; -use crate::{ErrorKind, Result, utils}; +use crate::{ErrorKind, Result}; use async_stream::try_stream; use futures::stream::Stream; use glob::glob_with; diff --git a/lychee-lib/src/utils/path.rs b/lychee-lib/src/utils/path.rs index c25745b..38a562b 100644 --- a/lychee-lib/src/utils/path.rs +++ b/lychee-lib/src/utils/path.rs @@ -2,7 +2,6 @@ use crate::{ErrorKind, Result}; use cached::proc_macro::cached; use path_clean::PathClean; use std::env; -use std::fs; use std::path::{Path, PathBuf}; use std::sync::LazyLock; @@ -51,26 +50,6 @@ pub(crate) fn resolve( Ok(Some(absolute_path(resolved))) } -/// Check if `child` is a subdirectory/file inside `parent` -/// -/// Note that `contains(parent, parent)` will return `true` -/// -/// See -/// See -/// -/// # Errors -/// -/// Returns an error if the `path` does not exist -/// or a non-final component in path is not a directory. -// -// Unfortunately requires real files for `fs::canonicalize`. -pub(crate) fn contains(parent: &PathBuf, child: &PathBuf) -> Result { - let parent = fs::canonicalize(parent)?; - let child = fs::canonicalize(child)?; - - Ok(child.starts_with(parent)) -} - #[cfg(test)] mod test_path { use super::*; @@ -114,48 +93,4 @@ mod test_path { ); Ok(()) } - - #[test] - fn test_contains() { - let parent_dir = tempfile::tempdir().unwrap(); - let parent = parent_dir.path(); - let child_dir = tempfile::tempdir_in(parent).unwrap(); - let child = child_dir.path(); - - assert_eq!(contains(&parent.to_owned(), &child.to_owned()), Ok(true)); - } - - #[test] - fn test_contains_not() { - let dir1 = tempfile::tempdir().unwrap(); - let dir2 = tempfile::tempdir().unwrap(); - - assert_eq!( - contains(&dir1.path().to_owned(), &dir2.path().to_owned()), - Ok(false) - ); - } - - #[test] - fn test_contains_one_dir_does_not_exist() { - let dir1 = tempfile::tempdir().unwrap(); - - assert!(matches!( - contains(&dir1.path().to_owned(), &PathBuf::from("/does/not/exist")), - Err(crate::ErrorKind::ReadStdinInput(_)) - )); - } - - // Relative paths are supported, e.g. - // parent: `/path/to/parent` - // child: `/path/to/parent/child/..` - #[test] - fn test_contains_one_dir_relative_path() { - let parent_dir = tempfile::tempdir().unwrap(); - let parent = parent_dir.path(); - let child_dir = tempfile::tempdir_in(parent).unwrap(); - let child = child_dir.path().join(".."); - - assert_eq!(contains(&parent.to_owned(), &child), Ok(true)); - } } diff --git a/lychee.example.toml b/lychee.example.toml index d190804..11ea162 100644 --- a/lychee.example.toml +++ b/lychee.example.toml @@ -104,10 +104,10 @@ include_verbatim = false # Ignore case of paths when matching glob patterns. glob_ignore_case = false -# Exclude URLs and mail addresses from checking (supports regex). +# Exclude URLs and mail addresses from checking. The values are treated as regular expressions exclude = ['^https://www\.linkedin\.com', '^https://web\.archive\.org/web/'] -# Exclude these filesystem paths from getting checked. +# Exclude paths from getting checked. The values are treated as regular expressions exclude_path = ["file/path/to/Ignore", "./other/file/path/to/Ignore"] # URLs to check (supports regex). Has preference over all excludes.