Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fmt:off with trailing child comment #8234

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Oct 26, 2023

Summary

This PR fixes the issue where Ruff dropped the trailing comment of the last child when using a fmt: off without a matching fmt: on.

# fmt: off
from dataclasses import dataclass

@dataclass
class A:
    x: int # Optional[int]

Got formatted to

# fmt: off
from dataclasses import dataclass

@dataclass
class A:
    x: int

The source of this was once again, that the class range does not include the range of nested comments.

Closes #8211

Test Plan

Added tests. The similarity index is unchanged.

@MichaReiser
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@MichaReiser MichaReiser force-pushed the fix-fmt-off-trailing-child-comment branch from 71dda55 to 123b4d6 Compare October 26, 2023 00:52
@MichaReiser MichaReiser marked this pull request as ready for review October 26, 2023 00:55
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You love this behavior

@MichaReiser MichaReiser added the formatter Related to the formatter label Oct 26, 2023
@MichaReiser MichaReiser enabled auto-merge (squash) October 26, 2023 00:58
@MichaReiser MichaReiser merged commit 6983d96 into main Oct 26, 2023
16 checks passed
@MichaReiser MichaReiser deleted the fix-fmt-off-trailing-child-comment branch October 26, 2023 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter removes comment at end of file if fmt: off is never closed
2 participants