fmt: off..on suppression comments (#6477)
This commit is contained in:
23
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/comments.py
vendored
Normal file
23
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/comments.py
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
|
||||
5
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/empty_file.py
vendored
Normal file
5
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/empty_file.py
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# fmt: off
|
||||
|
||||
# this does not work because there are no statements
|
||||
|
||||
# fmt: on
|
||||
19
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/fmt_off_docstring.py
vendored
Normal file
19
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/fmt_off_docstring.py
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
7
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/form_feed.py
vendored
Normal file
7
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/form_feed.py
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# fmt: off
|
||||
# DB layer (form feed at the start of the next line)
|
||||
|
||||
# fmt: on
|
||||
|
||||
def test():
|
||||
pass
|
||||
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/last_statement.py
vendored
Normal file
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/last_statement.py
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
def test():
|
||||
# fmt: off
|
||||
|
||||
a + b
|
||||
|
||||
|
||||
|
||||
# suppressed comments
|
||||
|
||||
a + b # formatted
|
||||
9
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/no_fmt_on.py
vendored
Normal file
9
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/no_fmt_on.py
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
def test():
|
||||
# fmt: off
|
||||
not formatted
|
||||
|
||||
if unformatted + a:
|
||||
pass
|
||||
|
||||
# Get's formatted again
|
||||
a + b
|
||||
71
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/off_on_off_on.py
vendored
Normal file
71
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/off_on_off_on.py
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# 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
|
||||
9
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/simple.py
vendored
Normal file
9
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/simple.py
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Get's formatted
|
||||
a + b
|
||||
|
||||
# fmt: off
|
||||
a + [1, 2, 3, 4, 5 ]
|
||||
# fmt: on
|
||||
|
||||
# Get's formatted again
|
||||
a + b
|
||||
40
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/trailing_comments.py
vendored
Normal file
40
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/trailing_comments.py
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
17
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/yapf.py
vendored
Normal file
17
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/yapf.py
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user