mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:47:41 +00:00
Format function and class definitions into a single line if its body is an ellipsis (#6592)
This commit is contained in:
parent
bb5fbb1b5c
commit
2a8d24dd4b
15 changed files with 445 additions and 60 deletions
102
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ellipsis.pyi
vendored
Normal file
102
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ellipsis.pyi
vendored
Normal file
|
@ -0,0 +1,102 @@
|
|||
"""Compound statements with no body should be written on one line."""
|
||||
|
||||
if True:
|
||||
...
|
||||
elif True:
|
||||
...
|
||||
else:
|
||||
...
|
||||
|
||||
if True:
|
||||
# comment
|
||||
...
|
||||
elif True:
|
||||
# comment
|
||||
...
|
||||
else:
|
||||
# comment
|
||||
...
|
||||
|
||||
if True:
|
||||
... # comment
|
||||
elif True:
|
||||
... # comment
|
||||
else:
|
||||
... # comment
|
||||
|
||||
for i in []:
|
||||
...
|
||||
else:
|
||||
...
|
||||
|
||||
for i in []:
|
||||
# comment
|
||||
...
|
||||
else:
|
||||
# comment
|
||||
...
|
||||
|
||||
for i in []:
|
||||
... # comment
|
||||
else:
|
||||
... # comment
|
||||
|
||||
while True:
|
||||
...
|
||||
else:
|
||||
...
|
||||
|
||||
while True:
|
||||
# comment
|
||||
...
|
||||
else:
|
||||
# comment
|
||||
...
|
||||
|
||||
while True:
|
||||
... # comment
|
||||
else:
|
||||
... # comment
|
||||
|
||||
with True:
|
||||
...
|
||||
|
||||
with True:
|
||||
# comment
|
||||
...
|
||||
|
||||
with True:
|
||||
... # comment
|
||||
|
||||
match x:
|
||||
case 1:
|
||||
...
|
||||
case 2:
|
||||
# comment
|
||||
...
|
||||
case 3:
|
||||
... # comment
|
||||
|
||||
try:
|
||||
...
|
||||
except:
|
||||
...
|
||||
finally:
|
||||
...
|
||||
|
||||
try:
|
||||
# comment
|
||||
...
|
||||
except:
|
||||
# comment
|
||||
...
|
||||
finally:
|
||||
# comment
|
||||
...
|
||||
|
||||
try:
|
||||
... # comment
|
||||
except:
|
||||
... # comment
|
||||
finally:
|
||||
... # comment
|
|
@ -76,3 +76,16 @@ class Test2(A):
|
|||
def b(): ...
|
||||
# comment
|
||||
def c(): ...
|
||||
|
||||
class EllipsisWithComment:
|
||||
... # comment
|
||||
|
||||
def function_with_comment():
|
||||
... # comment
|
||||
|
||||
class EllispsisWithMultipleTrailing: # trailing class comment
|
||||
... # trailing ellipsis comment
|
||||
|
||||
class EllipsisWithLeadingComment:
|
||||
# leading
|
||||
...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue