Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent indentation in JSX conditional blocks #16252

Open
christianlegge opened this issue May 3, 2024 · 0 comments
Open

Inconsistent indentation in JSX conditional blocks #16252

christianlegge opened this issue May 3, 2024 · 0 comments
Labels
area:binary expressions lang:jsx Issues affecting JSX (not general JS issues) status:needs discussion Issues needing discussion and a decision to be made before action can be taken

Comments

@christianlegge
Copy link

Prettier 3.2.5
Playground link

--parser babel

Input:

<>
	{modal.shown && modal.artifact && Object.prototype.hasOwnProperty.call(modal.artifact, "video") ? (
		<video controls autoPlay>
			<source src={modal.artifact?.video} type="video/mp4" />
		</video>
	) : (
		<img
			style={{ visibility: imageLoaded ? "visible" : "hidden" }}
			src={modal.artifact?.image}
			alt={modal.artifact?.name}
			className="h-1/2"
			onLoad={() => setImageLoaded(true)}
		/>
	)}
	{modal.shown && modal.artifact && Object.prototype.hasOwnProperty.call(modal.artifact, "audio") && (
		<video controls autoPlay height="60" style={{ aspectRatio: "5/1" }}>
			<source src={modal.artifact?.audio} type="audio/wav" />
			<track
				label="English"
				kind="captions"
				srcLang="en"
				src={modal.artifact?.subtitles}
				default
			/>
		</video>
	)}
</>

Output:

<>
  {modal.shown &&
  modal.artifact &&
  Object.prototype.hasOwnProperty.call(modal.artifact, "video") ? (
    <video controls autoPlay>
      <source src={modal.artifact?.video} type="video/mp4" />
    </video>
  ) : (
    <img
      style={{ visibility: imageLoaded ? "visible" : "hidden" }}
      src={modal.artifact?.image}
      alt={modal.artifact?.name}
      className="h-1/2"
      onLoad={() => setImageLoaded(true)}
    />
  )}
  {modal.shown &&
    modal.artifact &&
    Object.prototype.hasOwnProperty.call(modal.artifact, "audio") && (
      <video controls autoPlay height="60" style={{ aspectRatio: "5/1" }}>
        <source src={modal.artifact?.audio} type="audio/wav" />
        <track
          label="English"
          kind="captions"
          srcLang="en"
          src={modal.artifact?.subtitles}
          default
        />
      </video>
    )}
</>;

Expected output:

<>
  {modal.shown &&
  modal.artifact &&
  Object.prototype.hasOwnProperty.call(modal.artifact, "video") ? (
    <video controls autoPlay>
      <source src={modal.artifact?.video} type="video/mp4" />
    </video>
  ) : (
    <img
      style={{ visibility: imageLoaded ? "visible" : "hidden" }}
      src={modal.artifact?.image}
      alt={modal.artifact?.name}
      className="h-1/2"
      onLoad={() => setImageLoaded(true)}
    />
  )}
  {modal.shown &&
  modal.artifact &&
  Object.prototype.hasOwnProperty.call(modal.artifact, "audio") && (
    <video controls autoPlay height="60" style={{ aspectRatio: "5/1" }}>
      <source src={modal.artifact?.audio} type="audio/wav" />
      <track
        label="English"
        kind="captions"
        srcLang="en"
        src={modal.artifact?.subtitles}
        default
      />
    </video>
  )}
</>;

Why?

It doesn't make any sense to me that these two blocks indent differently, I'm not 100% sure whether it should follow the style of the upper or lower one, but the upper makes more sense to me given that the lower's closing brace ends up unaligned with its opening one.

@kachkaev kachkaev added status:needs discussion Issues needing discussion and a decision to be made before action can be taken lang:jsx Issues affecting JSX (not general JS issues) area:binary expressions labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:binary expressions lang:jsx Issues affecting JSX (not general JS issues) status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests

2 participants