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

Correctly handle fmt: skip comments without internal spaces (#2970)
authorRyan Siu <ryansiu@umich.edu>
Sat, 9 Apr 2022 20:52:45 +0000 (16:52 -0400)
committerGitHub <noreply@github.com>
Sat, 9 Apr 2022 20:52:45 +0000 (16:52 -0400)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
CHANGES.md
src/black/comments.py
tests/data/fmtskip7.py [new file with mode: 0644]
tests/test_format.py

index e168e24d76e2c0e25c1047ab44197f6721b1c27e..b21c319d5e0e9535c7814df2e9092fd36fb8fdd9 100644 (file)
@@ -10,6 +10,9 @@
 
 <!-- Changes that affect Black's stable style -->
 
 
 <!-- Changes that affect Black's stable style -->
 
+- Fix unstable formatting involving `# fmt: skip` comments without internal spaces
+  (#2970)
+
 ### Preview style
 
 <!-- Changes that affect Black's preview style -->
 ### Preview style
 
 <!-- Changes that affect Black's preview style -->
index 455326469f0f3b9c42764b0867fda22d121914dc..23bf87fca7cb8e9a1fea521417cc80241aabfbd6 100644 (file)
@@ -214,8 +214,11 @@ def generate_ignored_nodes(
     container: Optional[LN] = container_of(leaf)
     if comment.value in FMT_SKIP:
         prev_sibling = leaf.prev_sibling
     container: Optional[LN] = container_of(leaf)
     if comment.value in FMT_SKIP:
         prev_sibling = leaf.prev_sibling
-        if comment.value in leaf.prefix and prev_sibling is not None:
-            leaf.prefix = leaf.prefix.replace(comment.value, "")
+        # Need to properly format the leaf prefix to compare it to comment.value,
+        # which is also formatted
+        comments = list_comments(leaf.prefix, is_endmarker=False, preview=preview)
+        if comments and comment.value == comments[0].value and prev_sibling is not None:
+            leaf.prefix = ""
             siblings = [prev_sibling]
             while (
                 "\n" not in prev_sibling.prefix
             siblings = [prev_sibling]
             while (
                 "\n" not in prev_sibling.prefix
diff --git a/tests/data/fmtskip7.py b/tests/data/fmtskip7.py
new file mode 100644 (file)
index 0000000..15ac0ad
--- /dev/null
@@ -0,0 +1,11 @@
+a =     "this is some code"
+b =     5  #fmt:skip
+c = 9  #fmt: skip
+d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring"  #fmt:skip
+
+# output
+
+a = "this is some code"
+b =     5  # fmt:skip
+c = 9  # fmt: skip
+d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring"  # fmt:skip
index 51d8fb0a1035e2b142609ae804f69c0bfd5153a2..fd5f596b6d54b75065ef4ff0aab0287266936fde 100644 (file)
@@ -44,6 +44,7 @@ SIMPLE_CASES: List[str] = [
     "fmtskip4",
     "fmtskip5",
     "fmtskip6",
     "fmtskip4",
     "fmtskip5",
     "fmtskip6",
+    "fmtskip7",
     "fstring",
     "function",
     "function2",
     "fstring",
     "function",
     "function2",