mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Rename CommentPlacement#then_with
to or_else
(#6341)
Per nits in the PR.
This commit is contained in:
parent
1e3fe67ca5
commit
3a985dd71e
2 changed files with 5 additions and 5 deletions
|
@ -29,7 +29,7 @@ pub(super) fn place_comment<'a>(
|
||||||
|
|
||||||
// Change comment placement depending on the node type. These can be seen as node-specific
|
// Change comment placement depending on the node type. These can be seen as node-specific
|
||||||
// fixups.
|
// fixups.
|
||||||
comment.then_with(|comment| match comment.enclosing_node() {
|
comment.or_else(|comment| match comment.enclosing_node() {
|
||||||
AnyNodeRef::Parameters(arguments) => {
|
AnyNodeRef::Parameters(arguments) => {
|
||||||
handle_parameters_separator_comment(comment, arguments, locator)
|
handle_parameters_separator_comment(comment, arguments, locator)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ pub(super) fn place_comment<'a>(
|
||||||
}
|
}
|
||||||
AnyNodeRef::Keyword(_) => handle_dict_unpacking_comment(comment, locator),
|
AnyNodeRef::Keyword(_) => handle_dict_unpacking_comment(comment, locator),
|
||||||
AnyNodeRef::ExprDict(_) => handle_dict_unpacking_comment(comment, locator)
|
AnyNodeRef::ExprDict(_) => handle_dict_unpacking_comment(comment, locator)
|
||||||
.then_with(|comment| handle_bracketed_end_of_line_comment(comment, locator)),
|
.or_else(|comment| handle_bracketed_end_of_line_comment(comment, locator)),
|
||||||
AnyNodeRef::ExprIfExp(expr_if) => handle_expr_if_comment(comment, expr_if, locator),
|
AnyNodeRef::ExprIfExp(expr_if) => handle_expr_if_comment(comment, expr_if, locator),
|
||||||
AnyNodeRef::ExprSlice(expr_slice) => handle_slice_comments(comment, expr_slice, locator),
|
AnyNodeRef::ExprSlice(expr_slice) => handle_slice_comments(comment, expr_slice, locator),
|
||||||
AnyNodeRef::ExprStarred(starred) => {
|
AnyNodeRef::ExprStarred(starred) => {
|
||||||
|
@ -270,12 +270,12 @@ fn handle_own_line_comment_around_body<'a>(
|
||||||
|
|
||||||
// Check if we're between bodies and should attach to the following body.
|
// Check if we're between bodies and should attach to the following body.
|
||||||
handle_own_line_comment_between_branches(comment, preceding, locator)
|
handle_own_line_comment_between_branches(comment, preceding, locator)
|
||||||
.then_with(|comment| {
|
.or_else(|comment| {
|
||||||
// Otherwise, there's no following branch or the indentation is too deep, so attach to the
|
// Otherwise, there's no following branch or the indentation is too deep, so attach to the
|
||||||
// recursively last statement in the preceding body with the matching indentation.
|
// recursively last statement in the preceding body with the matching indentation.
|
||||||
handle_own_line_comment_after_branch(comment, preceding, locator)
|
handle_own_line_comment_after_branch(comment, preceding, locator)
|
||||||
})
|
})
|
||||||
.then_with(|comment| {
|
.or_else(|comment| {
|
||||||
// If the following node is the first in its body, and there's a non-trivia token between the
|
// If the following node is the first in its body, and there's a non-trivia token between the
|
||||||
// comment and the following node (like a parenthesis), then it means the comment is trailing
|
// comment and the following node (like a parenthesis), then it means the comment is trailing
|
||||||
// the preceding node, not leading the following one.
|
// the preceding node, not leading the following one.
|
||||||
|
|
|
@ -663,7 +663,7 @@ impl<'a> CommentPlacement<'a> {
|
||||||
///
|
///
|
||||||
/// Returns `self` when the placement is non-[`CommentPlacement::Default`]. Otherwise, calls the
|
/// Returns `self` when the placement is non-[`CommentPlacement::Default`]. Otherwise, calls the
|
||||||
/// function with the comment and returns the result.
|
/// function with the comment and returns the result.
|
||||||
pub(super) fn then_with<F: FnOnce(DecoratedComment<'a>) -> Self>(self, f: F) -> Self {
|
pub(super) fn or_else<F: FnOnce(DecoratedComment<'a>) -> Self>(self, f: F) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Self::Default(comment) => f(comment),
|
Self::Default(comment) => f(comment),
|
||||||
_ => self,
|
_ => self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue