From 90d4676dd7bf5f0ee0c33a7a48a6e127797803fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 24 May 2023 22:35:42 +0300 Subject: [PATCH] feat(cli): Strip `.in` suffix(es) `.in` is typically used for build system template input files, containing some placeholders to replace. In some cases, multiple rounds of replacements are used, each with their own `.in`, so remove all trailing instances of it before attempting a filename match. Closes https://github.com/crate-ci/typos/issues/727 --- crates/typos-cli/src/file_type.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/typos-cli/src/file_type.rs b/crates/typos-cli/src/file_type.rs index 4b044bc..afaff6f 100644 --- a/crates/typos-cli/src/file_type.rs +++ b/crates/typos-cli/src/file_type.rs @@ -107,7 +107,7 @@ impl Types { } pub fn file_matched(&self, path: &std::path::Path) -> Option<&str> { - let file_name = path.file_name()?; + let file_name = path.file_name()?.to_str()?.trim_end_matches(".in"); let mut matches = self.matches.get_or_default().borrow_mut(); self.set.matches_into(file_name, &mut *matches); matches @@ -153,6 +153,8 @@ mod tests { matched!(multi_def_2, types(), "index.htm", "html"); matched!(no_match, types(), "leftpad.ada", None); matched!(more_specific, types(), "package-lock.json", "lock"); + matched!(trailing_in, types(), "index.html.in", "html"); + matched!(trailing_in_in, types(), "index.html.in.in", "html"); macro_rules! sort { ($name:ident, $actual:expr, $expected:expr) => {