]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Ignore `# fmt: off` as inline comment
authorŁukasz Langa <lukasz@langa.pl>
Sun, 1 Apr 2018 06:50:27 +0000 (23:50 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Sun, 1 Apr 2018 07:08:09 +0000 (00:08 -0700)
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

README.md
black.py
tests/fmtonoff.py

index ff2c917e1e46b81f35f0d1fcadea3205503a950a..e5570252de1582a80fa39ec3e030ff5628dfa261 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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
   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
   freaks out with a flurry of asyncio-related exceptions
 
index 87e023157a0419480c6098482c9d3636eedf893f..2c61880dda24a23dc897523f9bd37c9dd29d7ac8 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1134,6 +1134,10 @@ class LineGenerator(Visitor[Line]):
                 yield from self.line()
                 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:
         """You are in a twisty little maze of passages."""
         v = self.visit_stmt
@@ -1537,7 +1541,12 @@ def generate_comments(leaf: Leaf) -> Iterator[Leaf]:
             raise FormatOn(consumed)
 
         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
 
index 4bacfcfd2d3d69d39bc70682a1268d5361361927..16c392595c0cf32a4b963d44cb574ce7ee54d38f 100644 (file)
@@ -71,6 +71,18 @@ def long_lines():
         $
         """, 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
 
@@ -175,3 +187,15 @@ def long_lines():
         """,
         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}