X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/2189bcaac01d9b6289411a75557a23cf4a06b783..196b1f349eb2baa9bbbc483226874cc01fb7567d:/src/black/comments.py?ds=inline diff --git a/src/black/comments.py b/src/black/comments.py index dce83ab..e733dcc 100644 --- a/src/black/comments.py +++ b/src/black/comments.py @@ -232,7 +232,7 @@ def generate_ignored_nodes( # fix for fmt: on in children if children_contains_fmt_on(container, preview=preview): - for child in container.children: + for index, child in enumerate(container.children): if isinstance(child, Leaf) and is_fmt_on(child, preview=preview): if child.type in CLOSING_BRACKETS: # This means `# fmt: on` is placed at a different bracket level @@ -241,6 +241,16 @@ def generate_ignored_nodes( # The alternative is to fail the formatting. yield child return + if ( + child.type == token.INDENT + and index < len(container.children) - 1 + and children_contains_fmt_on( + container.children[index + 1], preview=preview + ) + ): + # This means `# fmt: on` is placed right after an indentation + # level, and we shouldn't swallow the previous INDENT token. + return if children_contains_fmt_on(child, preview=preview): return yield child