Skip to content

Fix extra indentation for inline array/object in logical chains - #19792

Open
santhiprakash wants to merge 2 commits into
prettier:mainfrom
santhiprakash:fix/5183-nullish-coalescing-array-indent
Open

Fix extra indentation for inline array/object in logical chains#19792
santhiprakash wants to merge 2 commits into
prettier:mainfrom
santhiprakash:fix/5183-nullish-coalescing-array-indent

Conversation

@santhiprakash

@santhiprakash santhiprakash commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fix an extra level of indentation that Prettier adds to the contents of an array or object literal when it appears as the last operand of a logical chain (??, &&, ||) and every operand in the chain is an inline array/object/JSX literal.

When printBinaryishExpression determined it should use the chain layout, it wrapped the whole tail in indent(), which compounded with the array/object's own indentation. The new isInlineLogicalExpression helper checks whether the entire flattened chain consists of inline right-hand operands; if so, the outer indent() is skipped and the array/object contents align with the surrounding expression instead of being shifted one extra level.

Fixes #5183

Checklist

  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

When a logical chain (??/&&/||) ends with an array or object literal and
every operand in the chain is "inline", the binary printer was wrapping
the whole tail in an extra `indent()`. This caused the array/object
contents to be indented one level too deep relative to the surrounding
expression.

Add an `isInlineLogicalExpression` helper that checks the entire flattened
chain for inline right-hand operands, and skip the outer `indent()` when
the whole chain is inline. Existing behavior for chains that contain a
non-inline operand (which need the indent for the line break before the
operand) is preserved.

Fixes prettier#5183
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2fc57a9
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a73f1759974750008914d93
😎 Deploy Preview https://deploy-preview-19792--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@19792.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@19792.tgz
yarn add https://pkg.pr.new/@prettier/plugin-yuku@19792.tgz
yarn add https://pkg.pr.new/prettier@19792.tgz

commit: c6913cd

@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c6913cd
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a73f1841d28ea00087f8548
😎 Deploy Preview https://deploy-preview-19792--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extra indent for ?? and arrays

1 participant