-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Respect fmt: skip for compound statements on single line
#20633
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
base: main
Are you sure you want to change the base?
Conversation
|
c695437 to
aa2fd23
Compare
This seems unrelated to this PR as it is a pre-existing issue, right? |
MichaReiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great :) I suggest adding a few more tests with different comment placements. Just to make sure we handle them correctly.
| Ok(()) | ||
| }), | ||
| body, | ||
| SuiteKind::Class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we derive the SuiteKind from the ClauseHeader to reduce the number of arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so because I think we have to be told whether we're the last suite in the statement (but I think that's the only missing info)
crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__compound_one_liners.py.snap
Outdated
Show resolved
Hide resolved
crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__compound_one_liners.py.snap
Show resolved
Hide resolved
crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__compound_one_liners.py.snap
Show resolved
Hide resolved
aa2fd23 to
00d2823
Compare
|
The CI failure here https://github.com/astral-sh/ruff/actions/runs/18664070057/job/53211233008?pr=20633 was caused by this PR uncovering a pre-existing bug. See #21065 and #21067 . Will rebase once that PR is merged and then continue working on this! |
813abca to
6e1bb22
Compare
|
Cut down a comment-related hydra head and more grew in its place. This snippet causes a panic because the indented comment is not marked as formatted. Annoyingly it is attached to for x in it: foo()
# comment
else: bar() # fmt: skipConverting to draft while I sort it out 😄 |
8fc20dc to
91f1c9f
Compare
91f1c9f to
b5cde38
Compare
Closes #11216
Essentially the approach is to implement
Formatfor a new structFormatClausewhich is just a clause header and its body. We then have the information we need to see whether there is a skip suppression comment on the last child in the body and it all fits on one line.The
rufftest fixture (credit: mostly created by Claude) contains several lines that seem to crashblack, see:fix_fmt_skip_in_one_linersfor certain compound statements psf/black#4782fix_fmt_skip_in_one_linersfor function with annotated parameter and# fmt: skipon one line psf/black#4781and another line containing a deviation that I think is unintentional for
black, see:fix_fmt_skip_in_one_linersdoes not work for semi-colon separated statements in body of compound statement psf/black#4783However, it's not clear whether we want the same behavior here? In this PR we have:
unchanged, but we do add a newline between the statements here (unlike Black):
(see #11430 and #17331 .)
The other deviation from
blackis that we format the placement of the skip comment itself.For review, it is simplest to go commit by commit.