mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-20 18:40:51 +00:00
Fix formatter with-statement after-as own line comment instability (#6033)
**Summary** Fix an instability in with statement formatter when there is an own line comment as the `as` ```python with ( a as # bad comment b): ``` **Test Plan** Added the comment to the test cases.
This commit is contained in:
parent
a9f535997d
commit
7f3797185c
4 changed files with 44 additions and 11 deletions
|
@ -1370,15 +1370,15 @@ fn handle_with_item_comment<'a>(
|
|||
SimpleTokenKind::As,
|
||||
);
|
||||
|
||||
// If before the `as` keyword, then it must be a trailing comment of the context expression.
|
||||
if comment.end() < as_token.start() {
|
||||
// If before the `as` keyword, then it must be a trailing comment of the context expression.
|
||||
CommentPlacement::trailing(context_expr, comment)
|
||||
}
|
||||
// Trailing end of line comment coming after the `as` keyword`.
|
||||
else if comment.line_position().is_end_of_line() {
|
||||
CommentPlacement::dangling(comment.enclosing_node(), comment)
|
||||
} else {
|
||||
CommentPlacement::Default(comment)
|
||||
CommentPlacement::leading(optional_vars, comment)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue