Use correct indentation when project table contains open bracket comment (#8387)

## Summary

Now, we use four space (rather than one space) for cases like:

```toml
dependencies = [ # comment 0
    # comment 1
    "anyio==3.7.0", # comment 2
    # comment 3
]
```
This commit is contained in:
Charlie Marsh 2024-10-20 15:56:36 -04:00 committed by GitHub
parent 7e2822d694
commit 6ff674f5bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 9 deletions

View File

@ -893,16 +893,14 @@ fn reformat_array_multiline(deps: &mut Array) {
let decor_prefix = decor let decor_prefix = decor
.prefix() .prefix()
.and_then(|s| s.as_str()) .and_then(|s| s.as_str())
.map(|s| s.split('#').next().unwrap_or("")) .and_then(|s| s.lines().last())
.unwrap_or_default() .unwrap_or_default();
.trim_start_matches(['\r', '\n'].as_ref())
.to_string();
// If there is no indentation, use four-space. // If there is no indentation, use four-space.
indentation_prefix = Some(if decor_prefix.is_empty() { indentation_prefix = Some(if decor_prefix.is_empty() {
" ".to_string() " ".to_string()
} else { } else {
decor_prefix decor_prefix.to_string()
}); });
} }

View File

@ -6389,10 +6389,10 @@ fn add_preserves_open_bracket_comment() -> Result<()> {
version = "0.1.0" version = "0.1.0"
requires-python = ">=3.12" requires-python = ">=3.12"
dependencies = [ # comment 0 dependencies = [ # comment 0
# comment 1 # comment 1
"anyio==3.7.0", # comment 2 "anyio==3.7.0", # comment 2
# comment 3 # comment 3
"requests==2.31.0", "requests==2.31.0",
] ]
[build-system] [build-system]