Skip to content

Commit

Permalink
Use correct indentation when project table contains open bracket comment
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Oct 20, 2024
1 parent 30c1eb4 commit d364e20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions crates/uv-workspace/src/pyproject_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,16 +893,14 @@ fn reformat_array_multiline(deps: &mut Array) {
let decor_prefix = decor
.prefix()
.and_then(|s| s.as_str())
.map(|s| s.split('#').next().unwrap_or(""))
.unwrap_or_default()
.trim_start_matches(['\r', '\n'].as_ref())
.to_string();
.and_then(|s| s.lines().last())
.unwrap_or_default();

// If there is no indentation, use four-space.
indentation_prefix = Some(if decor_prefix.is_empty() {
" ".to_string()
} else {
decor_prefix
decor_prefix.to_string()
});
}

Expand Down
8 changes: 4 additions & 4 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6389,10 +6389,10 @@ fn add_preserves_open_bracket_comment() -> Result<()> {
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [ # comment 0
# comment 1
"anyio==3.7.0", # comment 2
# comment 3
"requests==2.31.0",
# comment 1
"anyio==3.7.0", # comment 2
# comment 3
"requests==2.31.0",
]
[build-system]
Expand Down

0 comments on commit d364e20

Please sign in to comment.