Ignore # fmt: off
as inline comment
Black cannot currently support this form due to its generator-based nature. This is mostly a problem for existing `# yapf: disable` usage as trailing comment. Fixes #95
This commit is contained in:
parent
4787294622
commit
2f260514f6
@ -426,6 +426,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
* fixed 18.3a4 regression: don't crash and burn on empty lines with
|
* fixed 18.3a4 regression: don't crash and burn on empty lines with
|
||||||
trailing whitespace (#80)
|
trailing whitespace (#80)
|
||||||
|
|
||||||
|
* fixed 18.3a4 regression: `# yapf: disable` usage as trailing comment
|
||||||
|
would cause Black to not emit the rest of the file (#95)
|
||||||
|
|
||||||
* when CTRL+C is pressed while formatting many files, Black no longer
|
* when CTRL+C is pressed while formatting many files, Black no longer
|
||||||
freaks out with a flurry of asyncio-related exceptions
|
freaks out with a flurry of asyncio-related exceptions
|
||||||
|
|
||||||
|
11
black.py
11
black.py
@ -1134,6 +1134,10 @@ def visit_unformatted(self, node: LN) -> Iterator[Line]:
|
|||||||
yield from self.line()
|
yield from self.line()
|
||||||
yield from self.visit(node)
|
yield from self.visit(node)
|
||||||
|
|
||||||
|
if node.type == token.ENDMARKER:
|
||||||
|
# somebody decided not to put a final `# fmt: on`
|
||||||
|
yield from self.line()
|
||||||
|
|
||||||
def __attrs_post_init__(self) -> None:
|
def __attrs_post_init__(self) -> None:
|
||||||
"""You are in a twisty little maze of passages."""
|
"""You are in a twisty little maze of passages."""
|
||||||
v = self.visit_stmt
|
v = self.visit_stmt
|
||||||
@ -1537,7 +1541,12 @@ def generate_comments(leaf: Leaf) -> Iterator[Leaf]:
|
|||||||
raise FormatOn(consumed)
|
raise FormatOn(consumed)
|
||||||
|
|
||||||
if comment in {"# fmt: off", "# yapf: disable"}:
|
if comment in {"# fmt: off", "# yapf: disable"}:
|
||||||
raise FormatOff(consumed)
|
if comment_type == STANDALONE_COMMENT:
|
||||||
|
raise FormatOff(consumed)
|
||||||
|
|
||||||
|
prev = preceding_leaf(leaf)
|
||||||
|
if not prev or prev.type in WHITESPACE: # standalone comment in disguise
|
||||||
|
raise FormatOff(consumed)
|
||||||
|
|
||||||
nlines = 0
|
nlines = 0
|
||||||
|
|
||||||
|
@ -71,6 +71,18 @@ def long_lines():
|
|||||||
$
|
$
|
||||||
""", re.MULTILINE | re.VERBOSE
|
""", re.MULTILINE | re.VERBOSE
|
||||||
)
|
)
|
||||||
|
def single_literal_yapf_disable():
|
||||||
|
"""Black does not support this."""
|
||||||
|
BAZ = {
|
||||||
|
(1, 2, 3, 4),
|
||||||
|
(5, 6, 7, 8),
|
||||||
|
(9, 10, 11, 12),
|
||||||
|
} # yapf: disable
|
||||||
|
# fmt: off
|
||||||
|
# No formatting to the end of the file
|
||||||
|
l=[1,2,3]
|
||||||
|
d={'a':1,
|
||||||
|
'b':2}
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
@ -175,3 +187,15 @@ def long_lines():
|
|||||||
""",
|
""",
|
||||||
re.MULTILINE | re.VERBOSE,
|
re.MULTILINE | re.VERBOSE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def single_literal_yapf_disable():
|
||||||
|
"""Black does not support this."""
|
||||||
|
BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
||||||
|
|
||||||
|
|
||||||
|
# fmt: off
|
||||||
|
# No formatting to the end of the file
|
||||||
|
l=[1,2,3]
|
||||||
|
d={'a':1,
|
||||||
|
'b':2}
|
||||||
|
Loading…
Reference in New Issue
Block a user