mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Attach dangling comments to the comprehension instead of the if
or iter
nodes (#7693)
This commit is contained in:
parent
e62e245c61
commit
e2ec42539b
13 changed files with 124 additions and 22 deletions
|
@ -2083,7 +2083,7 @@ fn handle_comprehension_comment<'a>(
|
|||
CommentPlacement::Default(comment)
|
||||
} else {
|
||||
// after the `for`
|
||||
CommentPlacement::dangling(comment.enclosing_node(), comment)
|
||||
CommentPlacement::dangling(comprehension, comment)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2106,7 +2106,7 @@ fn handle_comprehension_comment<'a>(
|
|||
// attach as dangling comments on the target
|
||||
// (to be rendered as leading on the "in")
|
||||
return if is_own_line {
|
||||
CommentPlacement::dangling(comment.enclosing_node(), comment)
|
||||
CommentPlacement::dangling(comprehension, comment)
|
||||
} else {
|
||||
// correctly trailing on the target
|
||||
CommentPlacement::Default(comment)
|
||||
|
@ -2126,7 +2126,7 @@ fn handle_comprehension_comment<'a>(
|
|||
CommentPlacement::Default(comment)
|
||||
} else {
|
||||
// after the `in` but same line, turn into trailing on the `in` token
|
||||
CommentPlacement::dangling(&comprehension.iter, comment)
|
||||
CommentPlacement::dangling(comprehension, comment)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2157,10 +2157,10 @@ fn handle_comprehension_comment<'a>(
|
|||
);
|
||||
if is_own_line {
|
||||
if last_end < comment.start() && comment.start() < if_token.start() {
|
||||
return CommentPlacement::dangling(if_node, comment);
|
||||
return CommentPlacement::dangling(comprehension, comment);
|
||||
}
|
||||
} else if if_token.start() < comment.start() && comment.start() < if_node.start() {
|
||||
return CommentPlacement::dangling(if_node, comment);
|
||||
return CommentPlacement::dangling(comprehension, comment);
|
||||
}
|
||||
last_end = if_node.end();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue