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
34 changed files with 1883 additions and 978 deletions

View 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

View File

@@ -0,0 +1,5 @@
# fmt: off
# this does not work because there are no statements
# fmt: on

View 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

View File

@@ -0,0 +1,7 @@
# fmt: off
# DB layer (form feed at the start of the next line)
# fmt: on
def test():
pass

View File

@@ -0,0 +1,10 @@
def test():
# fmt: off
a + b
# suppressed comments
a + b # formatted

View File

@@ -0,0 +1,9 @@
def test():
# fmt: off
not formatted
if unformatted + a:
pass
# Get's formatted again
a + b

View 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

View 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

View 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

View 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