Skip to content

Commit

Permalink
refactor: only use .mdsf-cache for .cs files
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Mar 23, 2024
1 parent b7e3851 commit 1efe487
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ pub mod zigfmt;

#[inline]
pub fn setup_snippet(code: &str, file_ext: &str) -> std::io::Result<NamedTempFile> {
let _ = std::fs::create_dir_all(".mdsf-cache");

let mut f = tempfile::Builder::new()
.rand_bytes(12)
.suffix(file_ext)
.prefix(
// ktlint wants PascalCase file names
if file_ext == Language::Kotlin.to_file_ext() {
"MdsfFile"
} else {
"mdsf"
},
)
.tempfile_in(".mdsf-cache")?;
let mut b = tempfile::Builder::new();

b.rand_bytes(12).suffix(file_ext).prefix(
// ktlint wants PascalCase file names
if file_ext == Language::Kotlin.to_file_ext() {
"MdsfFile"
} else {
"mdsf"
},
);

let mut f = if file_ext == ".cs" {
let _ = std::fs::create_dir_all(".mdsf-cache");
b.tempfile_in(".mdsf-cache")
} else {
b.tempfile()
}?;

f.write_all(code.as_bytes())?;
f.flush()?;
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/usort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn format_using_usort(
}

#[cfg(test)]
mod test_isort {
mod test_usort {
use crate::{formatters::setup_snippet, languages::Language};

use super::format_using_usort;
Expand Down

0 comments on commit 1efe487

Please sign in to comment.