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
31 changes: 16 additions & 15 deletions crates/oxc_formatter/src/utils/assignment_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,9 @@ fn is_poorly_breakable_member_or_call_chain<'a>(
let is_breakable_call = match args.len() {
0 => false,
1 => match args.iter().next() {
Some(first_argument) => !is_short_argument(first_argument, threshold, f),
Some(first_argument) => first_argument
.as_expression()
.is_none_or(|e| !is_short_argument(e, threshold, f)),
None => false,
},
_ => true,
Expand All @@ -945,15 +947,14 @@ fn is_poorly_breakable_member_or_call_chain<'a>(
/// We need it to decide if `JsCallExpression` with the argument is breakable or not
/// If the argument is short the function call isn't breakable
/// [Prettier applies]: <https://github.com/prettier/prettier/blob/a043ac0d733c4d53f980aa73807a63fc914f23bd/src/language-js/print/assignment.js#L374>
fn is_short_argument(argument: &Argument, threshold: u16, f: &Formatter) -> bool {
match argument {
Argument::Identifier(identifier) => identifier.name.len() <= threshold as usize,
Argument::UnaryExpression(unary_expression) => {
unary_expression.operator.is_arithmetic()
&& matches!(unary_expression.argument, Expression::NumericLiteral(_))
fn is_short_argument(expression: &Expression, threshold: u16, f: &Formatter) -> bool {
match expression {
Expression::Identifier(identifier) => identifier.name.len() <= threshold as usize,
Expression::UnaryExpression(unary_expression) => {
is_short_argument(&unary_expression.argument, threshold, f)
}
Argument::RegExpLiteral(regex) => regex.regex.pattern.text.len() <= threshold as usize,
Argument::StringLiteral(literal) => {
Expression::RegExpLiteral(regex) => regex.regex.pattern.text.len() <= threshold as usize,
Expression::StringLiteral(literal) => {
let formatter = FormatLiteralStringToken::new(
f.source_text().text_for(literal.as_ref()),
literal.span,
Expand All @@ -964,7 +965,7 @@ fn is_short_argument(argument: &Argument, threshold: u16, f: &Formatter) -> bool
formatter.clean_text(f.context().source_type(), f.options()).width()
<= threshold as usize
}
Argument::TemplateLiteral(literal) => {
Expression::TemplateLiteral(literal) => {
let elements = &literal.expressions;

// Besides checking length exceed we also need to check that the template doesn't have any expressions.
Expand All @@ -975,11 +976,11 @@ fn is_short_argument(argument: &Argument, threshold: u16, f: &Formatter) -> bool
raw.len() <= threshold as usize && !raw.contains('\n')
}
}
Argument::ThisExpression(_)
| Argument::NullLiteral(_)
| Argument::BigIntLiteral(_)
| Argument::BooleanLiteral(_)
| Argument::NumericLiteral(_) => true,
Expression::ThisExpression(_)
| Expression::NullLiteral(_)
| Expression::BigIntLiteral(_)
| Expression::BooleanLiteral(_)
| Expression::NumericLiteral(_) => true,
_ => false,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const requestTrie =
TernarySearchTree.forPaths<IRecursiveWatchRequest>(!isLinux);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
const requestTrie =
TernarySearchTree.forPaths<IRecursiveWatchRequest>(!isLinux);

==================== Output ====================
const requestTrie =
TernarySearchTree.forPaths<IRecursiveWatchRequest>(!isLinux);

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