From da86f6a294c2986276f850265f1b2d9bab5c91a9 Mon Sep 17 00:00:00 2001 From: Ryan Peach Date: Sat, 2 Nov 2024 19:38:57 -0400 Subject: [PATCH] Working well on my notes --- src/config.rs | 2 +- src/rules/duplicate_alias.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 7d3cccd..b606f29 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,7 +46,7 @@ pub struct Config { #[builder(default=r"-|_|\s".to_owned())] pub filename_spacing_pattern: String, /// See [`self::cli::Config::filename_match_threshold`] - #[builder(default = 95)] + #[builder(default = 100)] pub filename_match_threshold: i64, /// See [`self::cli::Config::exclude`] #[builder(default=vec![])] diff --git a/src/rules/duplicate_alias.rs b/src/rules/duplicate_alias.rs index c814059..3fe3a20 100644 --- a/src/rules/duplicate_alias.rs +++ b/src/rules/duplicate_alias.rs @@ -82,6 +82,8 @@ pub enum NewDuplicateAliasError { MissingSubstringError(#[from] MissingSubstringError), #[error(transparent)] ReplacePairError(#[from] ReplacePairError), + #[error("The file {filename} contains its own alias {alias}")] + AliasAndFilenameSame { filename: Filename, alias: Alias }, } #[derive(Error, Debug)] @@ -108,7 +110,14 @@ impl DuplicateAlias { file1_path: &PathBuf, file2_path: &PathBuf, ) -> Result { - assert_ne!(file1_path, file2_path); + // Boundary conditions + if file1_path == file2_path { + return Err(NewDuplicateAliasError::AliasAndFilenameSame { + filename: get_filename(file1_path.as_path()), + alias: alias.clone(), + }); + } + // Create the unique id let id = format!("{CODE}::{alias}");