Skip to content

Commit 1483f4c

Browse files
authored
refactor: Remove add_dummy_extension() helper (#682)
The helper method is redundant (_introduced as a [bug fix in Mar 2022](#306), there is a much simpler approach to append the extension. - [`as_mut_os_string()`](https://doc.rust-lang.org/std/path/struct.Path.html#method.as_mut_os_str) has been available since Rust `1.70.0`, matching the MSRV of this crate since the introduction of [`OnceLock`](https://doc.rust-lang.org/std/sync/struct.OnceLock.html) [in Oct 2024](#515) (_`0.14.1` release_). - Additionally revised the comment and included a conditional statement to better communicate the intent for why this placeholder is necessary.
2 parents a3182b0 + e5c0aa7 commit 1483f4c

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/file/source/file.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ impl FileSourceFile {
5959
)))
6060
};
6161
}
62-
// Adding a dummy extension will make sure we will not override secondary extensions, i.e. "file.local"
63-
// This will make the following set_extension function calls to append the extension.
64-
let mut filename = add_dummy_extension(filename);
62+
63+
let mut filename = filename;
64+
// Preserve any extension-like text within the provided file stem by appending a fake extension
65+
// which will be replaced by `set_extension()` calls (e.g. `file.local.placeholder` => `file.local.json`)
66+
if filename.extension().is_some() {
67+
filename.as_mut_os_string().push(".placeholder");
68+
}
6569

6670
match format_hint {
6771
Some(format) => {
@@ -134,18 +138,3 @@ where
134138
})
135139
}
136140
}
137-
138-
fn add_dummy_extension(mut filename: PathBuf) -> PathBuf {
139-
match filename.extension() {
140-
Some(extension) => {
141-
let mut ext = extension.to_os_string();
142-
ext.push(".");
143-
ext.push("dummy");
144-
filename.set_extension(ext);
145-
}
146-
None => {
147-
filename.set_extension("dummy");
148-
}
149-
}
150-
filename
151-
}

0 commit comments

Comments
 (0)