mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-22 21:25:27 +00:00
Fix finding keyword range for clause header after statement ending with semicolon (#21067)
When formatting clause headers for clauses that are not their own node, like an `else` clause or `finally` clause, we begin searching for the keyword at the end of the previous statement. However, if the previous statement ended in a semicolon this caused a panic because we only expected trivia between the end of the last statement and the keyword. This PR adjusts the starting point of our search for the keyword to begin after the optional semicolon in these cases. Closes #21065
This commit is contained in:
parent
db0e921db1
commit
116611bd39
3 changed files with 145 additions and 31 deletions
|
|
@ -42,3 +42,11 @@ def test4(<RANGE_START> a):
|
|||
|
||||
<RANGE_START>if b + c :<RANGE_END> # trailing clause header comment
|
||||
print("Not formatted" )
|
||||
|
||||
def test5():
|
||||
x = 1
|
||||
<RANGE_START>try:
|
||||
a;
|
||||
finally:
|
||||
b
|
||||
<RANGE_END>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue