diff --git a/crates/oxc_formatter/src/write/parameters.rs b/crates/oxc_formatter/src/write/parameters.rs index 1cea13f98fcec..ccb3fedfad82c 100644 --- a/crates/oxc_formatter/src/write/parameters.rs +++ b/crates/oxc_formatter/src/write/parameters.rs @@ -382,7 +382,14 @@ pub fn has_only_simple_parameters( parameters: &FormalParameters<'_>, allow_type_annotations: bool, ) -> bool { - parameters.items.iter().all(|parameter| is_simple_parameter(parameter, allow_type_annotations)) + // NOTE: A rest parameter is never considered simple. + // Prettier only checks `param.type` is `Identifier` or not. + // https://github.com/prettier/prettier/blob/7848357af654883e21ed05c0bbbedf89ee88750e/src/language-js/print/function.js#L72-L74 + parameters.rest.is_none() + && parameters + .items + .iter() + .all(|parameter| is_simple_parameter(parameter, allow_type_annotations)) } /// Tests if the single parameter is "simple", as in a plain identifier with no diff --git a/crates/oxc_formatter/tests/fixtures/ts/parameters/issue-17269.ts b/crates/oxc_formatter/tests/fixtures/ts/parameters/issue-17269.ts new file mode 100644 index 0000000000000..66ae43527d4d7 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/parameters/issue-17269.ts @@ -0,0 +1,6 @@ +useStableCallback(function useShowToast( + ...args: Parameters + ): void { + toastService.addToastItem(...args); + }); + diff --git a/crates/oxc_formatter/tests/fixtures/ts/parameters/issue-17269.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/parameters/issue-17269.ts.snap new file mode 100644 index 0000000000000..95b820939d5c8 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/parameters/issue-17269.ts.snap @@ -0,0 +1,31 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +useStableCallback(function useShowToast( + ...args: Parameters + ): void { + toastService.addToastItem(...args); + }); + + +==================== Output ==================== +------------------ +{ printWidth: 80 } +------------------ +useStableCallback(function useShowToast( + ...args: Parameters +): void { + toastService.addToastItem(...args); +}); + +------------------- +{ printWidth: 100 } +------------------- +useStableCallback(function useShowToast( + ...args: Parameters +): void { + toastService.addToastItem(...args); +}); + +===================== End =====================