-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 unstable formatting of trailing end-of-line comments of parenthesized attribute values #16187
Fix unstable formatting of trailing end-of-line comments of parenthesized attribute values #16187
Conversation
|
Thanks for fixing this! (BTW, I think the code examples in the PR description aren't quite the right ones.) 😄 |
28f8fc4
to
66a25a5
Compare
66a25a5
to
bab82b7
Compare
@huonw thanks for making me aware. I was in the middle of writing the summary and then realized that the fix wasn't ideal. So I decided to push what I had. |
@@ -1391,10 +1391,8 @@ fn handle_attribute_comment<'a>( | |||
.take_while(|token| token.kind == SimpleTokenKind::RParen) | |||
.last() | |||
{ | |||
return if comment.start() < right_paren.start() { | |||
CommentPlacement::trailing(attribute.value.as_ref(), comment) | |||
} else { |
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.
We want to fall through to the next case if the comment is after the closing parentheses
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'm a bit unfamiliar with fluent chain layout so it might good to get a second pair of eyes on this (Konsti?) but otherwise looks good.
( | ||
( | ||
a # trailing end-of-line | ||
# trailing own-line | ||
) # trailing closing parentheses | ||
# dangling before dot | ||
.b # trailing end-of-line | ||
) |
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.
What's the significance of this test case? It seems to be working fine on main
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 mainly wanted to make sure that I don't break this case.
Yeah. I don't think anyone is very familiar with this specific code at the moment :) |
* main: (60 commits) [`refurb`] Manual timezone monkeypatching (`FURB162`) (#16113) [`pyupgrade`] Do not upgrade functional TypedDicts with private field names to the class-based syntax (`UP013`) (#16219) Improve docs for PYI019 (#16229) Refactor `CallOutcome` to `Result` (#16161) Fix minor punctuation errors (#16228) Include document specific debug info (#16215) Update server to return the debug info as string (#16214) [`airflow`] Group `ImportPathMoved` and `ProviderName` to avoid misusing (`AIR303`) (#16157) Fix unstable formatting of trailing end-of-line comments of parenthesized attribute values (#16187) Ignore source code actions for a notebook cell (#16154) Add FAQ entry for `source.*` code actions in Notebook (#16212) red-knot: move symbol lookups in `symbol.rs` (#16152) better error messages while loading configuration `extend`s (#15658) Format `index.css` (#16207) Improve API exposed on `ExprStringLiteral` nodes (#16192) Update Rust crate tempfile to v3.17.0 (#16202) Update cloudflare/wrangler-action action to v3.14.0 (#16203) Update NPM Development dependencies (#16199) Update Rust crate smallvec to v1.14.0 (#16201) Update Rust crate codspeed-criterion-compat to v2.8.0 (#16200) ...
Summary
Fixes #16151
This fixes a formatter instability where it incorrectly moved a trailing end-of-line comment
of a parenthesized attribute value was moved to the next line:
Got reformatted to
and then finally to:
Not only is it an instability, but it also moves the
type: ignore
comment away from the node it was attributing.This PR fixes both by preserving the input formatting. Both those examples are correct formattings now:
I don't expect this to change any stable formatting because the formatter always moved trailing end-of-line comments and made them leading own-line comments of the
.
tokenTest Plan
Added tests, ecosystem check