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. |
| { | ||
| return if comment.start() < right_paren.start() { | ||
| CommentPlacement::trailing(attribute.value.as_ref(), comment) | ||
| } else { |
There was a problem hiding this comment.
We want to fall through to the next case if the comment is after the closing parentheses
dhruvmanila
left a comment
There was a problem hiding this comment.
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.
What's the significance of this test case? It seems to be working fine on main
There was a problem hiding this comment.
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: ignorecomment 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