mirror of
https://github.com/astral-sh/ruff
synced 2026-01-07 14:44:17 -05:00
Use correct start location for class/function clause header (#7802)
## Summary This PR fixes the bug where the formatter would panic if a class/function with decorators had a suppression comment. The fix is to use to correct start location to find the `async`/`def`/`class` keyword when decorators are present which is the end of the last decorator. ## Test Plan Add test cases for the fix and update the snapshots.
This commit is contained in:
@@ -23,6 +23,19 @@ class Test:
|
||||
def test():
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/7735
|
||||
@decorator1
|
||||
@decorator2
|
||||
class Foo: # fmt: skip
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/7735
|
||||
@decorator1
|
||||
@decorator2
|
||||
def foo(): # fmt: skip
|
||||
pass
|
||||
```
|
||||
|
||||
## Output
|
||||
@@ -43,6 +56,20 @@ class Test:
|
||||
# leading class comment
|
||||
def test():
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/7735
|
||||
@decorator1
|
||||
@decorator2
|
||||
class Foo: # fmt: skip
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/7735
|
||||
@decorator1
|
||||
@decorator2
|
||||
def foo(): # fmt: skip
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user