fmt: off..on suppression comments (#6477)

This commit is contained in:
Micha Reiser 2023-08-14 17:57:36 +02:00 committed by GitHub
parent 278a4f6e14
commit 09c8b17661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 1883 additions and 978 deletions

View file

@ -198,77 +198,7 @@ d={'a':1,
```diff
--- Black
+++ Ruff
@@ -6,8 +6,8 @@
from library import some_connection, some_decorator
# fmt: off
-from third_party import (X,
- Y, Z)
+from third_party import X, Y, Z
+
# fmt: on
f"trigger 3.6 mode"
# Comment 1
@@ -17,26 +17,40 @@
# fmt: off
def func_no_args():
- a; b; c
- if True: raise RuntimeError
- if False: ...
- for i in range(10):
- print(i)
- continue
- exec('new-style exec', {}, {})
- return None
+ a
+ b
+ c
+ if True:
+ raise RuntimeError
+ if False:
+ ...
+ for i in range(10):
+ print(i)
+ continue
+ exec("new-style exec", {}, {})
+ return None
+
+
async def coroutine(arg, exec=False):
- 'Single-line docstring. Multiline is harder to reformat.'
- async with some_connection() as conn:
- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
- await asyncio.sleep(1)
+ "Single-line docstring. Multiline is harder to reformat."
+ async with some_connection() as conn:
+ await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
+ await asyncio.sleep(1)
+
+
@asyncio.coroutine
-@some_decorator(
-with_args=True,
-many_args=[1,2,3]
-)
-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
- return text[number:-1]
+@some_decorator(with_args=True, many_args=[1, 2, 3])
+def function_signature_stress_test(
+ number: int,
+ no_annotation=None,
+ text: str = "default",
+ *,
+ debug: bool = False,
+ **kwargs,
+) -> str:
+ return text[number:-1]
+
+
# fmt: on
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
@@ -63,15 +77,15 @@
@@ -63,15 +63,15 @@
something = {
# fmt: off
@ -287,88 +217,28 @@ d={'a':1,
# fmt: on
goes + here,
andhere,
@@ -80,38 +94,42 @@
def import_as_names():
@@ -122,8 +122,10 @@
"""
# fmt: off
- from hello import a, b
- 'unformatted'
+ from hello import a, b
- # hey, that won't work
+ #hey, that won't work
+
+
+ "unformatted"
# fmt: on
pass
def testlist_star_expr():
# fmt: off
- a , b = *hello
- 'unformatted'
+ a, b = *hello
+ "unformatted"
# fmt: on
def yield_expr():
# fmt: off
yield hello
- 'unformatted'
+ "unformatted"
# fmt: on
"formatted"
# fmt: off
- ( yield hello )
- 'unformatted'
+ (yield hello)
+ "unformatted"
# fmt: on
def example(session):
# fmt: off
- result = session\
- .query(models.Customer.id)\
- .filter(models.Customer.account_id == account_id,
- models.Customer.email == email_address)\
- .order_by(models.Customer.id.asc())\
+ result = (
+ session.query(models.Customer.id)
+ .filter(
+ models.Customer.account_id == account_id,
+ models.Customer.email == email_address,
+ )
+ .order_by(models.Customer.id.asc())
.all()
+ )
# fmt: on
@@ -132,10 +150,10 @@
"""Another known limitation."""
@@ -138,7 +140,7 @@
now . considers . multiple . fmt . directives . within . one . prefix
# fmt: on
# fmt: off
- this=should.not_be.formatted()
- and_=indeed . it is not formatted
- because . the . handling . inside . generate_ignored_nodes()
- now . considers . multiple . fmt . directives . within . one . prefix
+ this = should.not_be.formatted()
+ and_ = indeed.it is not formatted
+ because.the.handling.inside.generate_ignored_nodes()
+ now.considers.multiple.fmt.directives.within.one.prefix
- # ...but comments still get reformatted even though they should not be
+ # ...but comments still get reformatted even though they should not be
# fmt: on
# fmt: off
# ...but comments still get reformatted even though they should not be
@@ -153,9 +171,7 @@
)
)
# fmt: off
- a = (
- unnecessary_bracket()
- )
+ a = unnecessary_bracket()
# fmt: on
_type_comment_re = re.compile(
r"""
@@ -178,7 +194,7 @@
@@ -178,7 +180,7 @@
$
""",
# fmt: off
@ -377,18 +247,6 @@ d={'a':1,
# fmt: on
)
@@ -216,8 +232,7 @@
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
)
# fmt: off
-yield 'hello'
+yield "hello"
# No formatting to the end of the file
-l=[1,2,3]
-d={'a':1,
- 'b':2}
+l = [1, 2, 3]
+d = {"a": 1, "b": 2}
```
## Ruff Output
@ -402,8 +260,8 @@ from third_party import X, Y, Z
from library import some_connection, some_decorator
# fmt: off
from third_party import X, Y, Z
from third_party import (X,
Y, Z)
# fmt: on
f"trigger 3.6 mode"
# Comment 1
@ -413,40 +271,26 @@ f"trigger 3.6 mode"
# fmt: off
def func_no_args():
a
b
c
if True:
raise RuntimeError
if False:
...
for i in range(10):
print(i)
continue
exec("new-style exec", {}, {})
return None
a; b; c
if True: raise RuntimeError
if False: ...
for i in range(10):
print(i)
continue
exec('new-style exec', {}, {})
return None
async def coroutine(arg, exec=False):
"Single-line docstring. Multiline is harder to reformat."
async with some_connection() as conn:
await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
await asyncio.sleep(1)
'Single-line docstring. Multiline is harder to reformat.'
async with some_connection() as conn:
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
await asyncio.sleep(1)
@asyncio.coroutine
@some_decorator(with_args=True, many_args=[1, 2, 3])
def function_signature_stress_test(
number: int,
no_annotation=None,
text: str = "default",
*,
debug: bool = False,
**kwargs,
) -> str:
return text[number:-1]
@some_decorator(
with_args=True,
many_args=[1,2,3]
)
def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
return text[number:-1]
# fmt: on
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
@ -490,42 +334,38 @@ def subscriptlist():
def import_as_names():
# fmt: off
from hello import a, b
"unformatted"
from hello import a, b
'unformatted'
# fmt: on
def testlist_star_expr():
# fmt: off
a, b = *hello
"unformatted"
a , b = *hello
'unformatted'
# fmt: on
def yield_expr():
# fmt: off
yield hello
"unformatted"
'unformatted'
# fmt: on
"formatted"
# fmt: off
(yield hello)
"unformatted"
( yield hello )
'unformatted'
# fmt: on
def example(session):
# fmt: off
result = (
session.query(models.Customer.id)
.filter(
models.Customer.account_id == account_id,
models.Customer.email == email_address,
)
.order_by(models.Customer.id.asc())
result = session\
.query(models.Customer.id)\
.filter(models.Customer.account_id == account_id,
models.Customer.email == email_address)\
.order_by(models.Customer.id.asc())\
.all()
)
# fmt: on
@ -536,7 +376,9 @@ def off_and_on_without_data():
"""
# fmt: off
# hey, that won't work
#hey, that won't work
# fmt: on
pass
@ -546,13 +388,13 @@ def on_and_off_broken():
"""Another known limitation."""
# fmt: on
# fmt: off
this = should.not_be.formatted()
and_ = indeed.it is not formatted
because.the.handling.inside.generate_ignored_nodes()
now.considers.multiple.fmt.directives.within.one.prefix
this=should.not_be.formatted()
and_=indeed . it is not formatted
because . the . handling . inside . generate_ignored_nodes()
now . considers . multiple . fmt . directives . within . one . prefix
# fmt: on
# fmt: off
# ...but comments still get reformatted even though they should not be
# ...but comments still get reformatted even though they should not be
# fmt: on
@ -567,7 +409,9 @@ def long_lines():
)
)
# fmt: off
a = unnecessary_bracket()
a = (
unnecessary_bracket()
)
# fmt: on
_type_comment_re = re.compile(
r"""
@ -628,10 +472,11 @@ cfg.rule(
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
)
# fmt: off
yield "hello"
yield 'hello'
# No formatting to the end of the file
l = [1, 2, 3]
d = {"a": 1, "b": 2}
l=[1,2,3]
d={'a':1,
'b':2}
```
## Black Output

View file

@ -1,201 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py
---
## Input
```py
import pytest
TmSt = 1
TmEx = 2
# fmt: off
# Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
@pytest.mark.parametrize('test', [
# Test don't manage the volume
[
('stuff', 'in')
],
])
def test_fader(test):
pass
def check_fader(test):
pass
def verify_fader(test):
# misaligned comment
pass
def verify_fader(test):
"""Hey, ho."""
assert test.passed()
def test_calculate_fades():
calcs = [
# one is zero/none
(0, 4, 0, 0, 10, 0, 0, 6, 10),
(None, 4, 0, 0, 10, 0, 0, 6, 10),
]
# fmt: on
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -5,36 +5,40 @@
# fmt: off
+
# Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
-@pytest.mark.parametrize('test', [
-
- # Test don't manage the volume
+@pytest.mark.parametrize(
+ "test",
[
- ('stuff', 'in')
+ # Test don't manage the volume
+ [("stuff", "in")],
],
-])
+)
def test_fader(test):
pass
+
def check_fader(test):
-
pass
+
def verify_fader(test):
- # misaligned comment
+ # misaligned comment
pass
+
def verify_fader(test):
"""Hey, ho."""
assert test.passed()
+
def test_calculate_fades():
calcs = [
# one is zero/none
- (0, 4, 0, 0, 10, 0, 0, 6, 10),
- (None, 4, 0, 0, 10, 0, 0, 6, 10),
+ (0, 4, 0, 0, 10, 0, 0, 6, 10),
+ (None, 4, 0, 0, 10, 0, 0, 6, 10),
]
# fmt: on
```
## Ruff Output
```py
import pytest
TmSt = 1
TmEx = 2
# fmt: off
# Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
@pytest.mark.parametrize(
"test",
[
# Test don't manage the volume
[("stuff", "in")],
],
)
def test_fader(test):
pass
def check_fader(test):
pass
def verify_fader(test):
# misaligned comment
pass
def verify_fader(test):
"""Hey, ho."""
assert test.passed()
def test_calculate_fades():
calcs = [
# one is zero/none
(0, 4, 0, 0, 10, 0, 0, 6, 10),
(None, 4, 0, 0, 10, 0, 0, 6, 10),
]
# fmt: on
```
## Black Output
```py
import pytest
TmSt = 1
TmEx = 2
# fmt: off
# Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
@pytest.mark.parametrize('test', [
# Test don't manage the volume
[
('stuff', 'in')
],
])
def test_fader(test):
pass
def check_fader(test):
pass
def verify_fader(test):
# misaligned comment
pass
def verify_fader(test):
"""Hey, ho."""
assert test.passed()
def test_calculate_fades():
calcs = [
# one is zero/none
(0, 4, 0, 0, 10, 0, 0, 6, 10),
(None, 4, 0, 0, 10, 0, 0, 6, 10),
]
# fmt: on
```

View file

@ -1,101 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py
---
## Input
```py
# fmt: off
x = [
1, 2,
3, 4,
]
# fmt: on
# fmt: off
x = [
1, 2,
3, 4,
]
# fmt: on
x = [
1, 2, 3, 4
]
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1,14 +1,18 @@
# fmt: off
x = [
- 1, 2,
- 3, 4,
+ 1,
+ 2,
+ 3,
+ 4,
]
# fmt: on
# fmt: off
x = [
- 1, 2,
- 3, 4,
+ 1,
+ 2,
+ 3,
+ 4,
]
# fmt: on
```
## Ruff Output
```py
# fmt: off
x = [
1,
2,
3,
4,
]
# fmt: on
# fmt: off
x = [
1,
2,
3,
4,
]
# fmt: on
x = [1, 2, 3, 4]
```
## Black Output
```py
# fmt: off
x = [
1, 2,
3, 4,
]
# fmt: on
# fmt: off
x = [
1, 2,
3, 4,
]
# fmt: on
x = [1, 2, 3, 4]
```

View file

@ -25,52 +25,48 @@ def f(): pass
```diff
--- Black
+++ Ruff
@@ -1,8 +1,12 @@
# fmt: off
-@test([
- 1, 2,
- 3, 4,
-])
+@test(
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ ]
+)
@@ -4,17 +4,10 @@
3, 4,
])
# fmt: on
def f():
pass
-def f():
- pass
-
+def f(): pass
-@test(
- [
- 1,
- 2,
- 3,
- 4,
- ]
-)
-def f():
- pass
+@test([
+ 1, 2,
+ 3, 4,
+])
+def f(): pass
```
## Ruff Output
```py
# fmt: off
@test(
[
1,
2,
3,
4,
]
)
@test([
1, 2,
3, 4,
])
# fmt: on
def f():
pass
def f(): pass
@test(
[
1,
2,
3,
4,
]
)
def f():
pass
@test([
1, 2,
3, 4,
])
def f(): pass
```
## Black Output

View file

@ -110,57 +110,7 @@ elif unformatted:
},
)
@@ -27,7 +26,7 @@
# Regression test for https://github.com/psf/black/issues/3026.
def test_func():
# yapf: disable
- if unformatted( args ):
+ if unformatted(args):
return True
# yapf: enable
elif b:
@@ -39,10 +38,10 @@
# Regression test for https://github.com/psf/black/issues/2567.
if True:
# fmt: off
- for _ in range( 1 ):
- # fmt: on
- print ( "This won't be formatted" )
- print ( "This won't be formatted either" )
+ for _ in range(1):
+ # fmt: on
+ print("This won't be formatted")
+ print("This won't be formatted either")
else:
print("This will be formatted")
@@ -52,14 +51,12 @@
async def call(param):
if param:
# fmt: off
- if param[0:4] in (
- "ABCD", "EFGH"
- ) :
+ if param[0:4] in ("ABCD", "EFGH"):
# fmt: on
- print ( "This won't be formatted" )
+ print("This won't be formatted")
elif param[0:4] in ("ZZZZ",):
- print ( "This won't be formatted either" )
+ print("This won't be formatted either")
print("This will be formatted")
@@ -68,13 +65,13 @@
class Named(t.Protocol):
# fmt: off
@property
- def this_wont_be_formatted ( self ) -> str: ...
+ def this_wont_be_formatted(self) -> str:
+ ...
@@ -74,7 +73,6 @@
class Factory(t.Protocol):
def this_will_be_formatted(self, **kwargs) -> Named:
...
@ -168,7 +118,7 @@ elif unformatted:
# fmt: on
@@ -82,6 +79,6 @@
@@ -82,6 +80,6 @@
if x:
return x
# fmt: off
@ -209,7 +159,7 @@ run(
# Regression test for https://github.com/psf/black/issues/3026.
def test_func():
# yapf: disable
if unformatted(args):
if unformatted( args ):
return True
# yapf: enable
elif b:
@ -221,10 +171,10 @@ def test_func():
# Regression test for https://github.com/psf/black/issues/2567.
if True:
# fmt: off
for _ in range(1):
# fmt: on
print("This won't be formatted")
print("This won't be formatted either")
for _ in range( 1 ):
# fmt: on
print ( "This won't be formatted" )
print ( "This won't be formatted either" )
else:
print("This will be formatted")
@ -234,12 +184,14 @@ class A:
async def call(param):
if param:
# fmt: off
if param[0:4] in ("ABCD", "EFGH"):
if param[0:4] in (
"ABCD", "EFGH"
) :
# fmt: on
print("This won't be formatted")
print ( "This won't be formatted" )
elif param[0:4] in ("ZZZZ",):
print("This won't be formatted either")
print ( "This won't be formatted either" )
print("This will be formatted")
@ -248,8 +200,7 @@ class A:
class Named(t.Protocol):
# fmt: off
@property
def this_wont_be_formatted(self) -> str:
...
def this_wont_be_formatted ( self ) -> str: ...
class Factory(t.Protocol):

View file

@ -1,64 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py
---
## Input
```py
a = 3
# fmt: off
b, c = 1, 2
d = 6 # fmt: skip
e = 5
# fmt: on
f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."]
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1,7 +1,7 @@
a = 3
# fmt: off
-b, c = 1, 2
-d = 6 # fmt: skip
+b, c = 1, 2
+d = 6 # fmt: skip
e = 5
# fmt: on
f = [
```
## Ruff Output
```py
a = 3
# fmt: off
b, c = 1, 2
d = 6 # fmt: skip
e = 5
# fmt: on
f = [
"This is a very long line that should be formatted into a clearer line ",
"by rearranging.",
]
```
## Black Output
```py
a = 3
# fmt: off
b, c = 1, 2
d = 6 # fmt: skip
e = 5
# fmt: on
f = [
"This is a very long line that should be formatted into a clearer line ",
"by rearranging.",
]
```

View file

@ -0,0 +1,60 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/comments.py
---
## Input
```py
pass
# fmt: off
# A comment that falls into the verbatim range
a + b # a trailing comment
# in between comments
# function comment
def test():
pass
# trailing comment that falls into the verbatim range
# fmt: on
a + b
def test():
pass
# fmt: off
# a trailing comment
```
## Output
```py
pass
# fmt: off
# A comment that falls into the verbatim range
a + b # a trailing comment
# in between comments
# function comment
def test():
pass
# trailing comment that falls into the verbatim range
# fmt: on
a + b
def test():
pass
# fmt: off
# a trailing comment
```

View file

@ -0,0 +1,24 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/empty_file.py
---
## Input
```py
# fmt: off
# this does not work because there are no statements
# fmt: on
```
## Output
```py
# fmt: off
# this does not work because there are no statements
# fmt: on
```

View file

@ -0,0 +1,52 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/fmt_off_docstring.py
---
## Input
```py
def test():
# fmt: off
""" This docstring does not
get formatted
"""
# fmt: on
but + this + does
def test():
# fmt: off
# just for fun
# fmt: on
# leading comment
""" This docstring gets formatted
""" # trailing comment
and_this + gets + formatted + too
```
## Output
```py
def test():
# fmt: off
""" This docstring does not
get formatted
"""
# fmt: on
but + this + does
def test():
# fmt: off
# just for fun
# fmt: on
# leading comment
"""This docstring gets formatted""" # trailing comment
and_this + gets + formatted + too
```

View file

@ -0,0 +1,28 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/form_feed.py
---
## Input
```py
# fmt: off
# DB layer (form feed at the start of the next line)
# fmt: on
def test():
pass
```
## Output
```py
# fmt: off
# DB layer (form feed at the start of the next line)
# fmt: on
def test():
pass
```

View file

@ -0,0 +1,35 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/last_statement.py
---
## Input
```py
def test():
# fmt: off
a + b
# suppressed comments
a + b # formatted
```
## Output
```py
def test():
# fmt: off
a + b
# suppressed comments
a + b # formatted
```

View file

@ -0,0 +1,33 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/no_fmt_on.py
---
## Input
```py
def test():
# fmt: off
not formatted
if unformatted + a:
pass
# Get's formatted again
a + b
```
## Output
```py
def test():
# fmt: off
not formatted
if unformatted + a:
pass
# Get's formatted again
a + b
```

View file

@ -0,0 +1,156 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/off_on_off_on.py
---
## Input
```py
# Tricky sequences of fmt off and on
# Formatted
a + b
# fmt: off
# not formatted 1
# fmt: on
a + b
# formatted
# fmt: off
# not formatted 1
# fmt: on
# not formatted 2
# fmt: off
a + b
# fmt: on
# fmt: off
# not formatted 1
# fmt: on
# formatted 1
# fmt: off
# not formatted 2
a + b
# fmt: on
# formatted
b + c
# fmt: off
a + b
# not formatted
# fmt: on
# formatted
a + b
# fmt: off
a + b
# not formatted 1
# fmt: on
# formatted
# fmt: off
# not formatted 2
a + b
# fmt: off
a + b
# not formatted 1
# fmt: on
# formatted
# leading
a + b
# fmt: off
# leading unformatted
def test ():
pass
# fmt: on
a + b
```
## Output
```py
# Tricky sequences of fmt off and on
# Formatted
a + b
# fmt: off
# not formatted 1
# fmt: on
a + b
# formatted
# fmt: off
# not formatted 1
# fmt: on
# not formatted 2
# fmt: off
a + b
# fmt: on
# fmt: off
# not formatted 1
# fmt: on
# formatted 1
# fmt: off
# not formatted 2
a + b
# fmt: on
# formatted
b + c
# fmt: off
a + b
# not formatted
# fmt: on
# formatted
a + b
# fmt: off
a + b
# not formatted 1
# fmt: on
# formatted
# fmt: off
# not formatted 2
a + b
# fmt: off
a + b
# not formatted 1
# fmt: on
# formatted
# leading
a + b
# fmt: off
# leading unformatted
def test ():
pass
# fmt: on
a + b
```

View file

@ -0,0 +1,32 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/simple.py
---
## Input
```py
# Get's formatted
a + b
# fmt: off
a + [1, 2, 3, 4, 5 ]
# fmt: on
# Get's formatted again
a + b
```
## Output
```py
# Get's formatted
a + b
# fmt: off
a + [1, 2, 3, 4, 5 ]
# fmt: on
# Get's formatted again
a + b
```

View file

@ -0,0 +1,96 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/trailing_comments.py
---
## Input
```py
a = 10
# fmt: off
# more format
def test(): ...
# fmt: on
b = 20
# Sequence of trailing comments that toggle between format on and off. The sequence ends with a `fmt: on`, so that the function gets formatted.
# formatted 1
# fmt: off
# not formatted
# fmt: on
# formatted comment
# fmt: off
# not formatted 2
# fmt: on
# formatted
def test2 ():
...
a = 10
# Sequence of trailing comments that toggles between format on and off. The sequence ends with a `fmt: off`, so that the function is not formatted.
# formatted 1
# fmt: off
# not formatted
# fmt: on
# formattd
# fmt: off
# not formatted
def test3 ():
...
# fmt: on
```
## Output
```py
a = 10
# fmt: off
# more format
def test(): ...
# fmt: on
b = 20
# Sequence of trailing comments that toggle between format on and off. The sequence ends with a `fmt: on`, so that the function gets formatted.
# formatted 1
# fmt: off
# not formatted
# fmt: on
# formatted comment
# fmt: off
# not formatted 2
# fmt: on
# formatted
def test2():
...
a = 10
# Sequence of trailing comments that toggles between format on and off. The sequence ends with a `fmt: off`, so that the function is not formatted.
# formatted 1
# fmt: off
# not formatted
# fmt: on
# formattd
# fmt: off
# not formatted
def test3 ():
...
# fmt: on
```

View file

@ -0,0 +1,48 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/yapf.py
---
## Input
```py
# Get's formatted
a + b
# yapf: disable
a + [1, 2, 3, 4, 5 ]
# yapf: enable
# Get's formatted again
a + b
# yapf: disable
a + [1, 2, 3, 4, 5 ]
# fmt: on
# Get's formatted again
a + b
```
## Output
```py
# Get's formatted
a + b
# yapf: disable
a + [1, 2, 3, 4, 5 ]
# yapf: enable
# Get's formatted again
a + b
# yapf: disable
a + [1, 2, 3, 4, 5 ]
# fmt: on
# Get's formatted again
a + b
```