From: Ɓukasz Langa Date: Wed, 20 Jun 2018 06:46:58 +0000 (-0700) Subject: More tests for `# fmt: off` X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/c2327c83b28aa9ae6e7ea7078f17033c23e34d9c More tests for `# fmt: off` Two more known limitations that I don't feel like solving now. Probably very low priority. --- diff --git a/black.py b/black.py index 0f966ae..f1b1c30 100644 --- a/black.py +++ b/black.py @@ -2577,6 +2577,9 @@ def convert_one_fmt_off_pair(node: Node) -> bool: continue ignored_nodes = list(generate_ignored_nodes(leaf)) + if not ignored_nodes: + continue + first = ignored_nodes[0] # Can be a container node with the `leaf`. parent = first.parent prefix = first.prefix diff --git a/tests/data/fmtonoff.py b/tests/data/fmtonoff.py index 373e5c7..74b52ec 100644 --- a/tests/data/fmtonoff.py +++ b/tests/data/fmtonoff.py @@ -53,6 +53,27 @@ def example(session): .order_by(models.Customer.id.asc())\ .all() # fmt: on +def off_and_on_without_data(): + """All comments here are technically on the same prefix. + + The comments between will be formatted. This is a known limitation. + """ + # fmt: off + + + #hey, that won't work + + + # fmt: on + pass +def on_and_off_broken(): + """Another known limitation.""" + # fmt: on + # fmt: off + this=should.not_be.formatted() + but=it is formatted + because . the . handling . inside . generate_ignored_nodes() + doesnt . consider . ordering . within . one . prefix def long_lines(): if True: typedargslist.extend( @@ -201,6 +222,29 @@ def example(session): # fmt: on +def off_and_on_without_data(): + """All comments here are technically on the same prefix. + + The comments between will be formatted. This is a known limitation. + """ + # fmt: off + + # hey, that won't work + + # fmt: on + pass + + +def on_and_off_broken(): + """Another known limitation.""" + # fmt: on + # fmt: off + this = should.not_be.formatted() + but = it is formatted + because.the.handling.inside.generate_ignored_nodes() + doesnt.consider.ordering.within.one.prefix + + def long_lines(): if True: typedargslist.extend(