diff --git a/crates/biome_js_formatter/src/js/expressions/call_arguments.rs b/crates/biome_js_formatter/src/js/expressions/call_arguments.rs index 919ce90b8136..7126ccb998be 100644 --- a/crates/biome_js_formatter/src/js/expressions/call_arguments.rs +++ b/crates/biome_js_formatter/src/js/expressions/call_arguments.rs @@ -1205,14 +1205,21 @@ fn is_multiline_template_only_args(arguments: &JsCallArguments) -> bool { /// useMemo(() => {}, []) /// ``` fn is_react_hook_with_deps_array(arguments: &JsCallArguments, comments: &JsComments) -> bool { + if arguments.args().len() > 3 || arguments.args().len() < 2 { + return false; + }; + use AnyJsExpression::*; let mut args = arguments.args().iter(); + if arguments.args().len() == 3 { + args.next(); + } match (args.next(), args.next()) { ( Some(Ok(AnyJsCallArgument::AnyJsExpression(JsArrowFunctionExpression(callback)))), Some(Ok(AnyJsCallArgument::AnyJsExpression(JsArrayExpression(deps)))), - ) if arguments.args().len() == 2 => { + ) => { if comments.has_comments(callback.syntax()) || comments.has_comments(deps.syntax()) { return false; } diff --git a/crates/biome_js_formatter/tests/specs/js/module/expression/call_arguments.js b/crates/biome_js_formatter/tests/specs/js/module/expression/call_arguments.js new file mode 100644 index 000000000000..8ca21bdd45df --- /dev/null +++ b/crates/biome_js_formatter/tests/specs/js/module/expression/call_arguments.js @@ -0,0 +1,3 @@ +useImperativeHandle(ref, () => { + return; +}, []); diff --git a/crates/biome_js_formatter/tests/specs/js/module/expression/call_arguments.js.snap b/crates/biome_js_formatter/tests/specs/js/module/expression/call_arguments.js.snap new file mode 100644 index 000000000000..25d247c78392 --- /dev/null +++ b/crates/biome_js_formatter/tests/specs/js/module/expression/call_arguments.js.snap @@ -0,0 +1,41 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: js/module/expression/call_arguments.js +--- +# Input + +```js +useImperativeHandle(ref, () => { + return; +}, []); + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +JSX quote style: Double Quotes +Quote properties: As needed +Trailing commas: All +Semicolons: Always +Arrow parentheses: Always +Bracket spacing: true +Bracket same line: false +Attribute Position: Auto +----- + +```js +useImperativeHandle(ref, () => { + return; +}, []); +```