Skip to content

Commit b37aaeb

Browse files
committed
fix(formatter): should break even if the right side of the assignment is a require when it has a leading own line comment (#14499)
1 parent 2a58447 commit b37aaeb

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

crates/oxc_formatter/src/utils/assignment_like.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<'a> AssignmentLike<'a, '_> {
324324
.callee
325325
.get_identifier_reference()
326326
.is_some_and(|ident| ident.name == "require")
327+
&& !f.comments().has_leading_own_line_comment(call_expression.span.start)
327328
{
328329
return AssignmentLikeLayout::NeverBreakAfterOperator;
329330
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
var longlonglonglonglonglong = /*#__PURE__*/_interopDefaultLegacy(aaaaaaaaaaaaaaa);
22
var short = /*#__PURE__*/_interopDefaultLegacy(b);
3+
4+
const jestPackageJson =
5+
// eslint-disable-next-line @typescript-eslint/no-require-imports
6+
require(jestPath);

crates/oxc_formatter/tests/fixtures/js/comments/assignments.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ source: crates/oxc_formatter/tests/fixtures/mod.rs
55
var longlonglonglonglonglong = /*#__PURE__*/_interopDefaultLegacy(aaaaaaaaaaaaaaa);
66
var short = /*#__PURE__*/_interopDefaultLegacy(b);
77

8+
const jestPackageJson =
9+
// eslint-disable-next-line @typescript-eslint/no-require-imports
10+
require(jestPath);
11+
812
==================== Output ====================
913
var longlonglonglonglonglong =
1014
/*#__PURE__*/ _interopDefaultLegacy(aaaaaaaaaaaaaaa);
1115
var short = /*#__PURE__*/ _interopDefaultLegacy(b);
1216

17+
const jestPackageJson =
18+
// eslint-disable-next-line @typescript-eslint/no-require-imports
19+
require(jestPath);
20+
1321
===================== End =====================

0 commit comments

Comments
 (0)