Skip to content

Commit

Permalink
Fix issue with fmt: skip (#2254)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
enzet committed Jun 2, 2021
1 parent 4005246 commit 2e4ac3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/black/comments.py
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/data/fmtskip6.py
@@ -0,0 +1,5 @@
class A:
def f(self):
for line in range(10):
if True:
pass # fmt: skip

0 comments on commit 2e4ac3e

Please sign in to comment.