mirror of
https://github.com/astral-sh/ruff
synced 2026-01-08 23:24:31 -05:00
[formatter] Stabilize fix for single-with-item formatting with trailing comment (#16603)
## Summary This PR stabilizies the fix for https://github.com/astral-sh/ruff/issues/14001 We try to only make breaking formatting changes once a year. However, the plan was to release this fix as part of Ruff 0.9 but I somehow missed it when promoting all other formatter changes. I think it's worth making an exception here considering that this is a bug fix, it improves readability, and it should be rare (very few files in a single project). Our version policy explicitly allows breaking formatter changes in any minor release and the idea of only making breaking formatter changes once a year is mainly to avoid multiple releases throughout the year that introduce large formatter changes Closes https://github.com/astral-sh/ruff/issues/14001 ## Test Plan Updated snapshot
This commit is contained in:
@@ -771,113 +771,42 @@ if True:
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14001
|
||||
with (
|
||||
(
|
||||
open(
|
||||
"some/path.txt",
|
||||
"rb",
|
||||
)
|
||||
if True
|
||||
else open("other/path.txt")
|
||||
open(
|
||||
"some/path.txt",
|
||||
"rb",
|
||||
)
|
||||
if True
|
||||
else open("other/path.txt")
|
||||
# Bar
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
with ( # trailing comment
|
||||
(
|
||||
open(
|
||||
"some/path.txt",
|
||||
"rb",
|
||||
)
|
||||
if True
|
||||
else open("other/path.txt")
|
||||
open(
|
||||
"some/path.txt",
|
||||
"rb",
|
||||
)
|
||||
if True
|
||||
else open("other/path.txt")
|
||||
# Bar
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
with (
|
||||
(
|
||||
open(
|
||||
"some/path.txt",
|
||||
"rb",
|
||||
)
|
||||
if True
|
||||
else open("other/path.txt")
|
||||
open(
|
||||
"some/path.txt",
|
||||
"rb",
|
||||
)
|
||||
if True
|
||||
else open("other/path.txt")
|
||||
# Bar
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
#### Preview changes
|
||||
```diff
|
||||
--- Stable
|
||||
+++ Preview
|
||||
@@ -377,42 +377,36 @@
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14001
|
||||
with (
|
||||
- (
|
||||
- open(
|
||||
- "some/path.txt",
|
||||
- "rb",
|
||||
- )
|
||||
- if True
|
||||
- else open("other/path.txt")
|
||||
+ open(
|
||||
+ "some/path.txt",
|
||||
+ "rb",
|
||||
)
|
||||
+ if True
|
||||
+ else open("other/path.txt")
|
||||
# Bar
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
with ( # trailing comment
|
||||
- (
|
||||
- open(
|
||||
- "some/path.txt",
|
||||
- "rb",
|
||||
- )
|
||||
- if True
|
||||
- else open("other/path.txt")
|
||||
+ open(
|
||||
+ "some/path.txt",
|
||||
+ "rb",
|
||||
)
|
||||
+ if True
|
||||
+ else open("other/path.txt")
|
||||
# Bar
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
with (
|
||||
- (
|
||||
- open(
|
||||
- "some/path.txt",
|
||||
- "rb",
|
||||
- )
|
||||
- if True
|
||||
- else open("other/path.txt")
|
||||
+ open(
|
||||
+ "some/path.txt",
|
||||
+ "rb",
|
||||
)
|
||||
+ if True
|
||||
+ else open("other/path.txt")
|
||||
# Bar
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
### Output 2
|
||||
```
|
||||
indent-style = space
|
||||
|
||||
Reference in New Issue
Block a user