Skip to content

Commit c5bbb75

Browse files
committed
Match original line ending on Windows
1 parent 6f5fc21 commit c5bbb75

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

rewatch/src/format.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,23 @@ fn format_files(bsc_exe: &Path, files: Vec<String>, check: bool) -> Result<()> {
9898

9999
if output.status.success() {
100100
let original_content = fs::read_to_string(file)?;
101-
let formatted_content = String::from_utf8_lossy(&output.stdout);
101+
let formatted_content = {
102+
let raw = String::from_utf8_lossy(&output.stdout);
103+
// On Windows, bsc writes CRLF to stdout (text mode).
104+
// Match the line ending style of the original file so we
105+
// don't introduce unwanted conversions.
106+
#[cfg(windows)]
107+
{
108+
let original_has_crlf = original_content.contains("\r\n");
109+
if !original_has_crlf && raw.contains("\r\n") {
110+
std::borrow::Cow::Owned(raw.replace("\r\n", "\n"))
111+
} else {
112+
raw
113+
}
114+
}
115+
#[cfg(not(windows))]
116+
{ raw }
117+
};
102118
if original_content != formatted_content {
103119
if check {
104120
eprintln!("[format check] {file}");

0 commit comments

Comments
 (0)