ruff/crates/ruff_python_formatter/src
konsti 46f8961292
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
```
2023-07-23 14:32:16 +02:00
..
comments Fix SimpleTokenizer's backward lexing of # (#5878) 2023-07-20 11:54:18 +02:00
expression Formatter: Add EmptyWithDanglingComments helper (#5951) 2023-07-23 14:32:16 +02:00
module Format ModExpression (#5689) 2023-07-11 16:41:10 +02:00
other Rename ruff_python_whitespace to ruff_python_trivia (#5886) 2023-07-19 11:48:27 -04:00
pattern Use dedicated structs in comparable.rs (#5042) 2023-06-13 03:57:34 +00:00
snapshots Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
statement Rename ruff_python_whitespace to ruff_python_trivia (#5886) 2023-07-19 11:48:27 -04:00
builders.rs Formatter: Add EmptyWithDanglingComments helper (#5951) 2023-07-23 14:32:16 +02:00
cli.rs Add a tool for shrinking failing examples (#5731) 2023-07-18 08:03:35 +00:00
context.rs Cover Black's is_aritmetic_like formatting (#5738) 2023-07-14 17:54:58 +02:00
generated.rs Type alias stub for formatter (#5880) 2023-07-19 17:28:07 +02:00
lib.rs Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
main.rs Add a formatter CLI for debugging (#4809) 2023-06-05 07:33:33 +00:00
options.rs Prefer the configured quote style 2023-06-26 14:24:25 +02:00
prelude.rs Accept any Into<AnyNodeRef> as Comments arguments (#5205) 2023-06-20 16:49:21 +00:00