mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-18 19:41:34 +00:00
less aggressively use preceding node as last_child
This commit is contained in:
parent
0251bd1203
commit
8b18899f2d
1 changed files with 21 additions and 2 deletions
|
|
@ -716,7 +716,7 @@ fn handle_own_line_comment_after_branch<'a>(
|
|||
// pass
|
||||
// ```
|
||||
//
|
||||
// Otherwise, the preceding node is the last statement in the body
|
||||
// Otherwise, the preceding node may be the last statement in the body
|
||||
// of the preceding branch, in which case we can take it as our
|
||||
// `last_child` here - e.g.
|
||||
//
|
||||
|
|
@ -728,7 +728,26 @@ fn handle_own_line_comment_after_branch<'a>(
|
|||
// else:
|
||||
// pass
|
||||
// ```
|
||||
let last_child = preceding.last_child_in_body().unwrap_or(preceding);
|
||||
let last_child = match preceding.last_child_in_body() {
|
||||
Some(last) => last,
|
||||
None if matches!(
|
||||
comment.enclosing_node(),
|
||||
AnyNodeRef::StmtIf(_)
|
||||
| AnyNodeRef::StmtWhile(_)
|
||||
| AnyNodeRef::StmtFor(_)
|
||||
| AnyNodeRef::StmtMatch(_)
|
||||
| AnyNodeRef::ElifElseClause(_)
|
||||
| AnyNodeRef::StmtTry(_)
|
||||
| AnyNodeRef::MatchCase(_)
|
||||
| AnyNodeRef::ExceptHandlerExceptHandler(_)
|
||||
) =>
|
||||
{
|
||||
preceding
|
||||
}
|
||||
_ => {
|
||||
return CommentPlacement::Default(comment);
|
||||
}
|
||||
};
|
||||
|
||||
// We only care about the length because indentations with mixed spaces and tabs are only valid if
|
||||
// the indent-level doesn't depend on the tab width (the indent level must be the same if the tab width is 1 or 8).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue