Skip to content

Commit

Permalink
If you use underscores in your file name you still need to alias it w…
Browse files Browse the repository at this point in the history
…ith spaces
  • Loading branch information
ryanpeach committed Jan 6, 2025
1 parent a37543d commit 9c5e28f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mdlinker"
version = "1.6.0"
version = "1.6.1"
edition = "2021"

[profile.dev]
Expand Down
24 changes: 11 additions & 13 deletions src/rules/duplicate_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,17 @@ impl Visitor for DuplicateAliasVisitor {
// If it did not exist, we have a new alias in our table
if let Some(out) = self.alias_table.insert(alias.clone(), path.into()) {
self.duplicate_aliases.insert(alias.clone());
self.duplicate_alias_errors.push(DuplicateAlias::new(
let found = DuplicateAlias::new(
&alias,
path,
Some(source),
&out,
None,
&self.filename_to_alias,
)?);
)?;
if let Some(found) = found {
self.duplicate_alias_errors.push(found);
}
}
}

Expand Down Expand Up @@ -185,8 +188,6 @@ pub enum NewDuplicateAliasError {
CalculateError(#[from] CalculateError),
#[error(transparent)]
ReplacePairError(#[from] ReplacePairCompilationError),
#[error("The file {filename} contains its own alias {alias}")]
AliasAndFilenameSame { filename: Filename, alias: Alias },
}

impl DuplicateAlias {
Expand All @@ -203,14 +204,11 @@ impl DuplicateAlias {
file2_path: &Path,
file2_content: Option<&str>,
filename_to_alias: &ReplacePair<Filename, Alias>,
) -> Result<Self, NewDuplicateAliasError> {
) -> Result<Option<Self>, NewDuplicateAliasError> {
assert!(!alias.to_string().is_empty());
// Boundary conditions
if file1_path == file2_path {
return Err(NewDuplicateAliasError::AliasAndFilenameSame {
filename: get_filename(file1_path),
alias: alias.clone(),
});
return Ok(None);
}

// Create the unique id
Expand Down Expand Up @@ -242,13 +240,13 @@ impl DuplicateAlias {
alias.to_string().len(),
);

Ok(DuplicateAlias::FileNameContentDuplicate {
Ok(Some(DuplicateAlias::FileNameContentDuplicate {
id: id.into(),
other_filename: get_filename(file1_path),
src: NamedSource::new(file2_path.to_string_lossy(), file2_content.to_string()),
alias: file2_content_span,
advice: format!("Delete the alias from {}", file2_path.to_string_lossy()),
})
}))
} else if Alias::from_filename(&get_filename(file2_path), filename_to_alias) == *alias {
Self::new(
alias,
Expand Down Expand Up @@ -287,7 +285,7 @@ impl DuplicateAlias {
alias.to_string().len(),
);

Ok(DuplicateAlias::FileContentContentDuplicate {
Ok(Some(DuplicateAlias::FileContentContentDuplicate {
advice: format!("id: {id:?}"),
id: id.clone().into(),
other_filename: get_filename(file2_path),
Expand All @@ -301,7 +299,7 @@ impl DuplicateAlias {
alias: file2_content_span,
other: vec![],
}],
})
}))
}
}
}

0 comments on commit 9c5e28f

Please sign in to comment.