mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
Formatter: Add EmptyWithDanglingComments helper (#5951)
**Summary** Add a `EmptyWithDanglingComments` format helper that formats comments inside empty parentheses, brackets or curly braces. Previously, this was implemented separately, and partially incorrectly, for each use case. Empty `()`, `[]` and `{}` are special because there can be dangling comments, and they can be in two positions: ```python x = [ # end-of-line # own line ] ``` These comments are dangling because they can't be assigned to any element inside as they would in all other cases. **Test Plan** Added a regression test. 145 (from previously 149) instances of unstable formatting remaining. ``` $ cargo run --bin ruff_dev --release -- format-dev --stability-check --error-file formatter-ecosystem-errors.txt --multi-project target/checkouts > formatter-ecosystem-progress.txt $ rg "Unstable formatting" target/formatter-ecosystem-errors.txt | wc -l 145 ```
This commit is contained in:
parent
f886b58c92
commit
46f8961292
9 changed files with 94 additions and 56 deletions
|
@ -62,6 +62,9 @@ a = {
|
|||
# comment
|
||||
3: True,
|
||||
}
|
||||
|
||||
x={ # dangling end of line comment
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -126,6 +129,9 @@ a = {
|
|||
# comment
|
||||
3: True,
|
||||
}
|
||||
|
||||
x = { # dangling end of line comment
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -76,6 +76,9 @@ del (
|
|||
# Deleted
|
||||
) # Completed
|
||||
# Done
|
||||
|
||||
del ( # dangling end of line comment
|
||||
)
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -211,6 +214,9 @@ del (
|
|||
# Deleted
|
||||
) # Completed
|
||||
# Done
|
||||
|
||||
del ( # dangling end of line comment
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue