]> 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:

Possible fix for issue with indentation and fmt: skip (#2281)
authorSergey Vartanov <me@enzet.ru>
Tue, 8 Jun 2021 21:37:34 +0000 (00:37 +0300)
committerGitHub <noreply@github.com>
Tue, 8 Jun 2021 21:37:34 +0000 (14:37 -0700)
Not sure the fix is right.  Here is what I found: issue is connected
with line

    first.prefix = prefix[comment.consumed :]

in `comments.py`.  `first.prefix` is a prefix of the line, that ends
with `# fmt: skip`, but `comment.consumed` is the length of the
`"  # fmt: skip"` string.  If prefix length is greater than 14,
`first.prefix` will grow every time we apply formatting.

Fixes #2254

CHANGES.md
src/black/comments.py
tests/data/fmtskip6.py [new file with mode: 0644]
tests/test_format.py

index 02b3fdf75d5027001006ea55ec099cb7f6b7035a..2d2b3b4cf49303d1c33cf1f8e09b35525327034f 100644 (file)
@@ -4,6 +4,7 @@
 
 ### _Black_
 
+- Fix failure caused by `fmt: skip` and indentation (#2281)
 - Account for += assignment when deciding whether to split string (#2312)
 - Correct max string length calculation when there are string operators (#2292)
 - Fixed option usage when using the `--code` flag (#2259)
index 415e391b2a7270d5047bd948fa15d823f29a0b2e..c7513c21ef5693cb5e5800eecbbc94a3fab88e7c 100644 (file)
@@ -159,7 +159,10 @@ def convert_one_fmt_off_pair(node: Node) -> bool:
             first = ignored_nodes[0]  # Can be a container node with the `leaf`.
             parent = first.parent
             prefix = first.prefix
-            first.prefix = prefix[comment.consumed :]
+            if comment.value in FMT_OFF:
+                first.prefix = prefix[comment.consumed :]
+            if comment.value in FMT_SKIP:
+                first.prefix = ""
             hidden_value = "".join(str(n) for n in ignored_nodes)
             if comment.value in FMT_OFF:
                 hidden_value = comment.value + "\n" + hidden_value
diff --git a/tests/data/fmtskip6.py b/tests/data/fmtskip6.py
new file mode 100644 (file)
index 0000000..0a779fc
--- /dev/null
@@ -0,0 +1,13 @@
+class A:
+    def f(self):
+        for line in range(10):
+            if True:
+                pass  # fmt: skip
+
+# output
+
+class A:
+    def f(self):
+        for line in range(10):
+            if True:
+                pass  # fmt: skip
index 5c78afe0ba686f35fdfc0de44779c6ecaa115371..fc9678ad27cda3c0e6791f54c0bcf6858c24e5c6 100644 (file)
@@ -41,6 +41,7 @@ SIMPLE_CASES = [
     "fmtskip3",
     "fmtskip4",
     "fmtskip5",
+    "fmtskip6",
     "fstring",
     "function",
     "function2",