Skip to content

Fix fmt:off with trailing child comment#8234

Merged
MichaReiser merged 1 commit intomainfrom
fix-fmt-off-trailing-child-comment
Oct 26, 2023
Merged

Fix fmt:off with trailing child comment#8234
MichaReiser merged 1 commit intomainfrom
fix-fmt-off-trailing-child-comment

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
@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