Repository: prettier/prettier
File: src/language-js/print/call-arguments.js (JavaScript)

Code before:
  iterateCallArgumentsPath,
  shouldPrintComma,
} from "../utils/index.js";
import { isConciselyPrintedArray } from "./array.js";

function printCallArguments(path, options, print) {
  const { node } = path;

  const args = getCallArguments(node);
  if (args.length === 0) {
    return ["(", printDanglingComments(path, options), ")"];
  }

  // useEffect(() => { ... }, [foo, bar, baz])
  // useImperativeHandle(ref, () => { ... }, [foo, bar, baz])
  if (isReactHookCallWithDepsArray(args)) {
    const contents = [];

    for (let i = 0; i < args.length; i++) {
      contents.push(print(["arguments", i]));
      if (i !== args.length - 1) {
        contents.push(", ");
      }
    }

    return ["(", ...contents, ")"];
  }

  let anyArgEmptyLine = false;
  const lastArgIndex = args.length - 1;
  const printedArguments = [];
  iterateCallArgumentsPath(path, ({ node: arg }, index) => {
    let argDoc = print();

    if (index === lastArgIndex) {
      // do nothing
    } else if (isNextLineEmpty(arg, options)) {
      anyArgEmptyLine = true;
      argDoc = [argDoc, ",", hardline, hardline];
    } else {
      argDoc = [argDoc, ",", line];
    }

    printedArguments.push(argDoc);
  });

  // Dynamic imports cannot have trailing commas
  const isDynamicImport =
    node.type === "ImportExpression" || node.callee.type === "Import";
  const maybeTrailingComma =
    !isDynamicImport && shouldPrintComma(options, "all") ? "," : "";

Review comment (suggestion):
Please don't use needless spread syntax.

```suggestion
    const parts = ["("];
    for (let i = 0; i < args.length; i++) {
      parts.push(print(["arguments", i]));
      if (i !== args.length - 1) {
        parts.push(", ");
      }
    }
    parts.push(")");
    return parts;
```

Code after:
  iterateCallArgumentsPath,
  shouldPrintComma,
} from "../utils/index.js";
import { isConciselyPrintedArray } from "./array.js";

function printCallArguments(path, options, print) {
  const { node } = path;

  const args = getCallArguments(node);
  if (args.length === 0) {
    return ["(", printDanglingComments(path, options), ")"];
  }

  const lastArgIndex = args.length - 1;

  // useEffect(() => { ... }, [foo, bar, baz])
  // useImperativeHandle(ref, () => { ... }, [foo, bar, baz])
  if (isReactHookCallWithDepsArray(args)) {
    const parts = ["("];
    iterateCallArgumentsPath(path, (path, index) => {
      parts.push(print());
      if (index !== lastArgIndex) {
        parts.push(", ");
      }
    });
    parts.push(")");
    return parts;
  }

  let anyArgEmptyLine = false;
  const printedArguments = [];
  iterateCallArgumentsPath(path, ({ node: arg }, index) => {
    let argDoc = print();

    if (index === lastArgIndex) {
      // do nothing
    } else if (isNextLineEmpty(arg, options)) {
      anyArgEmptyLine = true;
      argDoc = [argDoc, ",", hardline, hardline];
    } else {
      argDoc = [argDoc, ",", line];
    }

    printedArguments.push(argDoc);
  });

  // Dynamic imports cannot have trailing commas
  const isDynamicImport =
    node.type === "ImportExpression" || node.callee.type === "Import";
  const maybeTrailingComma =
    !isDynamicImport && shouldPrintComma(options, "all") ? "," : "";