mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
Format ExpressionStarred
nodes (#5654)
This commit is contained in:
parent
9f486fa841
commit
987111f5fb
16 changed files with 192 additions and 581 deletions
|
@ -38,6 +38,7 @@ pub(super) fn place_comment<'a>(
|
|||
handle_slice_comments,
|
||||
handle_attribute_comment,
|
||||
handle_expr_if_comment,
|
||||
handle_trailing_expression_starred_star_end_of_line_comment,
|
||||
];
|
||||
for handler in HANDLERS {
|
||||
comment = match handler(comment, locator) {
|
||||
|
@ -1215,6 +1216,21 @@ fn handle_expr_if_comment<'a>(
|
|||
CommentPlacement::Default(comment)
|
||||
}
|
||||
|
||||
fn handle_trailing_expression_starred_star_end_of_line_comment<'a>(
|
||||
comment: DecoratedComment<'a>,
|
||||
_locator: &Locator,
|
||||
) -> CommentPlacement<'a> {
|
||||
if comment.line_position().is_own_line() || comment.following_node().is_none() {
|
||||
return CommentPlacement::Default(comment);
|
||||
}
|
||||
|
||||
let AnyNodeRef::ExprStarred(starred) = comment.enclosing_node() else {
|
||||
return CommentPlacement::Default(comment);
|
||||
};
|
||||
|
||||
CommentPlacement::leading(starred.as_any_node_ref(), comment)
|
||||
}
|
||||
|
||||
/// Looks for a token in the range that contains no other tokens except for parentheses outside
|
||||
/// the expression ranges
|
||||
fn find_only_token_in_range(range: TextRange, locator: &Locator, token_kind: TokenKind) -> Token {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue