dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

Keep bracket of jsx expression in a single new line

Open otakustay opened this issue 9 months ago • 3 comments

If we have a code like:

function Ok() {
    return (
        <div>
            {
                isThisConditionOk
                    ? (
                        <p><strong>Yes</strong></p>
                    )
                    : (
                        <p><strong>No</strong></p>
                    )
            }
            </div>
    );
}

We expect it to be unchanged, actually it is formatted like:

function Ok() {
  return (
    <div>
      {isThisConditionOk
        ? (
          <p>
            <strong>Yes</strong>
          </p>
        )
        : (
          <p>
            <strong>No</strong>
          </p>
        )}
    </div>
  );
}

Line breaks after { and before } are deleted, this cause unpaired indentation and hard-to-read )}.

Expression in jsx attribute has the same behavior:

function Ok() {
    return (
        <div
            render={
                work(
                    nice,
                    to,
                    have
                )
            }
        />
    );
}

is unexpectedly formatted to:

function Ok() {
  return (
    <div
      render={work(
        nice,
        to,
        have,
      )}
    />
  );
}

Meybe we can have a new option to force { and } in a standalone new line

otakustay avatar Nov 09 '23 08:11 otakustay

Don't forget to vote on this issue. I am looking for exactly the same.

Bessonov avatar Dec 25 '23 18:12 Bessonov

I am willing to implement this feature if we can get confirmation (from a maintainer) that it is desired.

This is currently one of the few formatting idiosyncrasies (compared to prettier/biomejs) that are keeping my team from switching to dprint's formatter.

John-Paul-R avatar Mar 17 '24 19:03 John-Paul-R

@dsherret Would you be willing to accept such a contribution?

John-Paul-R avatar Apr 05 '24 13:04 John-Paul-R