mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-12 07:35:07 +00:00
Remove newline-insertion logic from JoinNodesBuilder
(#6205)
## Summary This PR moves the "insert empty lines" behavior out of `JoinNodesBuilder` and into the `Suite` formatter. I find it a little confusing that the logic is split between those two formatters right now, and since this is _only_ used in that one place, IMO it is a bit simpler to just inline it and use a single approach to tracking state (right now, both are stateful). The only other place this was used was for decorators. As a side effect, we now remove blank lines in both of these cases, which is a known but intentional deviation from Black (which preserves the empty line before the comment in the first case): ```python @foo # Hello @bar def baz(): pass @foo @bar def baz(): pass ```
This commit is contained in:
parent
6ee5cb37c0
commit
615337a54d
4 changed files with 111 additions and 303 deletions
|
@ -151,7 +151,15 @@ def bar():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -106,7 +106,6 @@
|
||||
@@ -74,7 +74,6 @@
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
-
|
||||
# leading 3 that already has an empty line
|
||||
@deco3
|
||||
# leading 4
|
||||
@@ -106,7 +105,6 @@
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
|
@ -159,7 +167,7 @@ def bar():
|
|||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
@@ -121,7 +120,6 @@
|
||||
@@ -121,7 +119,6 @@
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
|
@ -248,7 +256,6 @@ some = statement
|
|||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
|
||||
# leading 3 that already has an empty line
|
||||
@deco3
|
||||
# leading 4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue