mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Fix instable formatting for trailing subscribt end-of-line comment (#10492)
## Summary This PR fixes an instability where formatting a subscribt where the `slice` is not an `ExprSlice` and it has a trailing end-of-line comment after its opening `[` required two formatting passes to be stable. The fix is to associate the trailing end-of-line comment as dangling comment on `[` to preserve its position, similar to how Ruff does it for other parenthesized expressions. This also matches how trailing end-of-line subscript comments are handled when the `slice` is an `ExprSlice`. Fixes https://github.com/astral-sh/ruff/issues/10355 ## Versioning Shipping this as part of a patch release is fine because: * It fixes a stability issue * It doesn't impact already formatted code because Ruff would already have moved to the comment to the end of the line (instead of preserving it) ## Test Plan Added tests
This commit is contained in:
parent
7caf0d064a
commit
954a48b129
3 changed files with 113 additions and 6 deletions
|
@ -3,3 +3,29 @@ result = (
|
|||
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
||||
+ 1
|
||||
)[0]
|
||||
|
||||
|
||||
# Regression tests for: https://github.com/astral-sh/ruff/issues/10355
|
||||
repro(
|
||||
"some long string that takes up some space"
|
||||
)[ # some long comment also taking up space
|
||||
0
|
||||
]
|
||||
|
||||
repro(
|
||||
"some long string that takes up some space"
|
||||
)[0 # some long comment also taking up space
|
||||
]
|
||||
|
||||
repro(
|
||||
"some long string that takes up some space"
|
||||
)[0] # some long comment also taking up space
|
||||
|
||||
repro("some long string that takes up some space")[0] # some long comment also taking up space
|
||||
|
||||
|
||||
repro(
|
||||
"some long string that takes up some space"
|
||||
)[ # some long comment also taking up space
|
||||
0:-1
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue