mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Use one line between top-level items if formatting a stub file (#6501)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
455db84a59
commit
84d178a219
7 changed files with 451 additions and 2 deletions
|
@ -161,7 +161,11 @@ fn format() {
|
|||
});
|
||||
};
|
||||
|
||||
insta::glob!("../resources", "test/fixtures/ruff/**/*.py", test_file);
|
||||
insta::glob!(
|
||||
"../resources",
|
||||
"test/fixtures/ruff/**/*.{py,pyi}",
|
||||
test_file
|
||||
);
|
||||
}
|
||||
|
||||
/// Format another time and make sure that there are no changes anymore
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/top_level.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
class A:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
class B:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
class Del(expr_context): ...
|
||||
class Load(expr_context): ...
|
||||
|
||||
# Some comment.
|
||||
class Other(expr_context): ...
|
||||
class Store(expr_context): ...
|
||||
class Foo(Bar): ...
|
||||
|
||||
class Baz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
class Quux(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# Some comment.
|
||||
class Quuz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def bar(): ...
|
||||
def baz(): ...
|
||||
def quux():
|
||||
"""Some docstring."""
|
||||
|
||||
def quuz():
|
||||
"""Some docstring."""
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
class A:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class B:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
|
||||
class Del(expr_context):
|
||||
...
|
||||
|
||||
|
||||
class Load(expr_context):
|
||||
...
|
||||
|
||||
|
||||
# Some comment.
|
||||
class Other(expr_context):
|
||||
...
|
||||
|
||||
|
||||
class Store(expr_context):
|
||||
...
|
||||
|
||||
|
||||
class Foo(Bar):
|
||||
...
|
||||
|
||||
|
||||
class Baz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Quux(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
# Some comment.
|
||||
class Quuz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def bar():
|
||||
...
|
||||
|
||||
|
||||
def baz():
|
||||
...
|
||||
|
||||
|
||||
def quux():
|
||||
"""Some docstring."""
|
||||
|
||||
|
||||
def quuz():
|
||||
"""Some docstring."""
|
||||
```
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/top_level.pyi
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
class A:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class B:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
|
||||
class Del(expr_context):
|
||||
...
|
||||
|
||||
|
||||
class Load(expr_context):
|
||||
...
|
||||
|
||||
|
||||
# Some comment.
|
||||
class Other(expr_context):
|
||||
...
|
||||
|
||||
|
||||
class Store(expr_context):
|
||||
...
|
||||
|
||||
|
||||
class Foo(Bar):
|
||||
...
|
||||
|
||||
|
||||
class Baz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Quux(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
# Some comment.
|
||||
class Quuz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def bar():
|
||||
...
|
||||
|
||||
|
||||
def baz():
|
||||
...
|
||||
|
||||
|
||||
def quux():
|
||||
"""Some docstring."""
|
||||
|
||||
|
||||
def quuz():
|
||||
"""Some docstring."""
|
||||
|
||||
def a():
|
||||
...
|
||||
|
||||
class Test:
|
||||
...
|
||||
|
||||
class Test2(A):
|
||||
...
|
||||
|
||||
def b(): ...
|
||||
# comment
|
||||
def c(): ...
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
class A:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
class B:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
class Del(expr_context):
|
||||
...
|
||||
class Load(expr_context):
|
||||
...
|
||||
|
||||
# Some comment.
|
||||
class Other(expr_context):
|
||||
...
|
||||
class Store(expr_context):
|
||||
...
|
||||
class Foo(Bar):
|
||||
...
|
||||
|
||||
class Baz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
class Quux(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# Some comment.
|
||||
class Quuz(Qux):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def bar():
|
||||
...
|
||||
def baz():
|
||||
...
|
||||
def quux():
|
||||
"""Some docstring."""
|
||||
|
||||
def quuz():
|
||||
"""Some docstring."""
|
||||
|
||||
def a():
|
||||
...
|
||||
|
||||
class Test:
|
||||
...
|
||||
class Test2(A):
|
||||
...
|
||||
|
||||
def b():
|
||||
...
|
||||
|
||||
# comment
|
||||
def c():
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue