mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-21 11:00:31 +00:00
Break with
on end-of-line trailing comments (#7685)
## Summary Ensures that: ```python with ( a # comment ): pass ``` Retains its parentheses. Closes https://github.com/astral-sh/ruff/issues/6750. ## Test Plan `cargo test`
This commit is contained in:
parent
58b50a6290
commit
a6d79c03b3
3 changed files with 118 additions and 12 deletions
|
@ -84,9 +84,9 @@ impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
|||
}))
|
||||
.fmt(f)?;
|
||||
} else if let [item] = item.items.as_slice() {
|
||||
// This is similar to `maybe_parenthesize_expression`, but we're not dealing with an
|
||||
// expression here, it's a `WithItem`.
|
||||
if comments.has_leading(item) || comments.has_trailing_own_line(item) {
|
||||
// This is similar to `maybe_parenthesize_expression`, but we're not
|
||||
// dealing with an expression here, it's a `WithItem`.
|
||||
if comments.has_leading(item) || comments.has_trailing(item) {
|
||||
optional_parentheses(&item.format()).fmt(f)?;
|
||||
} else {
|
||||
item.format().fmt(f)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue