diff --git a/CHANGES.md b/CHANGES.md index 4cbc3d8..65bcab1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ - Fix crash while formatting a long `del` statement containing tuples (#4628) - Fix crash while formatting expressions using the walrus operator in complex `with` statements (#4630) +- Handle `# fmt: skip` followed by a comment at the end of file (#4635) ### Preview style diff --git a/src/black/comments.py b/src/black/comments.py index 1054e7a..81d3cfd 100644 --- a/src/black/comments.py +++ b/src/black/comments.py @@ -321,7 +321,7 @@ def _generate_ignored_nodes_from_fmt_skip( if not comments or comment.value != comments[0].value: return if prev_sibling is not None: - leaf.prefix = "" + leaf.prefix = leaf.prefix[comment.consumed :] if Preview.fix_fmt_skip_in_one_liners not in mode: siblings = [prev_sibling] diff --git a/tests/data/cases/fmtskip11.py b/tests/data/cases/fmtskip11.py new file mode 100644 index 0000000..5d3f787 --- /dev/null +++ b/tests/data/cases/fmtskip11.py @@ -0,0 +1,6 @@ +def foo(): + pass + + +# comment 1 # fmt: skip +# comment 2