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:
Charlie Marsh 2023-07-31 16:58:15 -04:00 committed by GitHub
parent 6ee5cb37c0
commit 615337a54d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 111 additions and 303 deletions

View file

@ -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