Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions crates/oxc_formatter/src/write/arrow_function_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,18 @@ impl<'a> Format<'a> for FormatJsArrowFunctionExpression<'a, '_> {
};
}

#[expect(clippy::match_same_arms)]
let body_has_soft_line_break = arrow_expression.is_none_or(|expression| {
match expression {
let body_has_soft_line_break =
arrow_expression.is_none_or(|expression| match expression {
Expression::ArrowFunctionExpression(_)
| Expression::ArrayExpression(_)
| Expression::ObjectExpression(_) => {
// TODO: It seems no difference whether check there is a leading comment or not.
// !f.comments().has_leading_own_line_comment(body.span().start)
true
!f.comments().has_leading_own_line_comment(body.span().start)
}
Expression::JSXElement(_) | Expression::JSXFragment(_) => true,
_ => {
is_multiline_template_starting_on_same_line(expression, f.source_text())
}
}
});
});

let body_is_condition_type =
matches!(arrow_expression, Some(Expression::ConditionalExpression(_)));
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/comments/arrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
() =>
// comment
[];

() =>
// comment
({})
22 changes: 22 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/comments/arrow.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
() =>
// comment
[];

() =>
// comment
({})

==================== Output ====================
() =>
// comment
[];

() =>
// comment
({});

===================== End =====================
Loading