Skip to content

Ruff formatter ignoring fmt: skip #17331

@madduck

Description

@madduck

Summary

Taking this over from #8415:

I have a little snippet that inserts ipdb into code, and I want to keep it on a single line, so that I can easily remove it again with Vim dd, here is the test-case:

def main() -> None:
    import ipdb; ipdb.set_trace()  # noqa: E402,E702,I001 fmt: skip

This passes ruff's check alright:

% ruff --isolated check test.py --fix 
All checks passed!

But when I run the formatter on it, it seems that fmt: skip is being ignored:

% ruff --isolated format test.py --diff
--- test.py
+++ test.py
@@ -1,2 +1,4 @@
 def main() -> None:
-    import ipdb; ipdb.set_trace()  # noqa: E402 E702 I001 # fmt: skip
+    import ipdb
+
+    ipdb.set_trace()  # noqa: E402 E702 I001 # fmt: skip

1 file would be reformatted

I have tried # fmt: skip before and after the noqa filter, I have tried two spaces before the #, and I have tried without noqa, i.e. just # fmt: skip, with and without a space after the colon — the same result for each of these permutations.

If I enclose the line in fmt:off and fmt:on statements, then the formatter finds nothing to do, but that defies the purpose of the single-line import, and the per-line fmt:skip instruction.

Version

0.11.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformatterRelated to the formatter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions