mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 13:05:06 +00:00
Fix binary expression formatting with leading comments (#4964)
This commit is contained in:
parent
1accbeffd6
commit
646ab64850
3 changed files with 37 additions and 3 deletions
|
@ -90,9 +90,8 @@ impl FormatNodeRule<ExprBinOp> for FormatExprBinOp {
|
|||
]
|
||||
)?;
|
||||
|
||||
// Format the operator on its own line if the operator has trailing comments and the right side has leading comments.
|
||||
if !operator_comments.is_empty() && comments.has_leading_comments(right.as_ref().into())
|
||||
{
|
||||
// Format the operator on its own line if the right side has any leading comments.
|
||||
if comments.has_leading_comments(right.as_ref().into()) {
|
||||
write!(f, [hard_line_break()])?;
|
||||
} else if needs_space {
|
||||
write!(f, [space()])?;
|
||||
|
|
|
@ -47,6 +47,17 @@ not (aaaaaaaaaaaaaa + {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
|||
# comment
|
||||
content + b
|
||||
)
|
||||
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaa +
|
||||
# has the child process finished?
|
||||
bbbbbbbbbbbbbbb +
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
ccccccccccc
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
@ -105,6 +116,19 @@ NOT_YET_IMPLEMENTED_ExprUnaryOp
|
|||
content
|
||||
+ b
|
||||
)
|
||||
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaa
|
||||
+
|
||||
# has the child process finished?
|
||||
bbbbbbbbbbbbbbb
|
||||
+
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
ccccccccccc
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue