From a541d6cf70307b258ccb325201315c6f9836b35b Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 23 Sep 2024 09:58:24 -0400 Subject: [PATCH] Avoid adding double-newlines for CRLF (#7640) ## Summary Closes https://github.com/astral-sh/uv/issues/7621. --- crates/uv-workspace/src/pyproject_mut.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/uv-workspace/src/pyproject_mut.rs b/crates/uv-workspace/src/pyproject_mut.rs index f2eafb327107..de2952648284 100644 --- a/crates/uv-workspace/src/pyproject_mut.rs +++ b/crates/uv-workspace/src/pyproject_mut.rs @@ -694,17 +694,18 @@ fn reformat_array_multiline(deps: &mut Array) { for item in deps.iter_mut() { let decor = item.decor_mut(); let mut prefix = String::new(); - // calculating the indentation prefix as the indentation of the first dependency entry + + // Calculate the indentation prefix based on the indentation of the first dependency entry. if indentation_prefix.is_none() { let decor_prefix = decor .prefix() .and_then(|s| s.as_str()) - .map(|s| s.split('#').next().unwrap_or("").to_string()) - .unwrap_or(String::new()) - .trim_start_matches('\n') + .map(|s| s.split('#').next().unwrap_or("")) + .unwrap_or_default() + .trim_start_matches(['\r', '\n'].as_ref()) .to_string(); - // if there is no indentation then apply a default one + // If there is no indentation, use four-space. indentation_prefix = Some(if decor_prefix.is_empty() { " ".to_string() } else {