Visitar URL original
Fix extra indentation for inline array/object in logical chains by santhiprakash · Pull Request #19792 · prettier/prettier · GitHub
Skip to content

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

Merged
fisker merged 2 commits into
prettier:mainfrom
santhiprakash:fix/5183-nullish-coalescing-array-indent
Oct 13, 2026
Merged

fisker merged 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.

santhiprakash added a commit to santhiprakash/prettier that referenced this pull request Aug 6, 2026
@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: c122c42

@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 c122c42
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a7d1525868d870008880af3
😎 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.

santhiprakash added a commit to santhiprakash/prettier that referenced this pull request Aug 12, 2026
@santhiprakash
santhiprakash force-pushed the fix/5183-nullish-coalescing-array-indent branch 2 times, most recently from ec081c1 to 7f41a3d Compare August 12, 2026 23:29
santhiprakash added a commit to santhiprakash/prettier that referenced this pull request Aug 12, 2026
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
@santhiprakash
santhiprakash force-pushed the fix/5183-nullish-coalescing-array-indent branch from 7f41a3d to c122c42 Compare August 13, 2026 00:51
@fisker fisker added this to the 3.10 milestone Aug 25, 2026
@fisker

fisker commented Aug 25, 2026

Copy link
Copy Markdown
Member

Waiting for regression test. prettier/prettier-regression-testing#731 (comment)

@santhiprakash

Copy link
Copy Markdown
Contributor Author

Regression test completed — triggered via the standard command on prettier/prettier-regression-testing#731:

Run #19792

Full result: prettier/prettier-regression-testing#731 (comment) (workflow run), executed against this PR's current head (c122c42).

21/24 projects: empty diff. The three non-empty diffs are explained by the comparison baseline — prettier/prettier@main at run time was ~130 commits ahead of this branch's merge-base (8f2e4a6, 2026-08-13) — not by this change:

Nothing in the report is attributable to this PR: the only source change is src/language-js/print/binaryish.js (indentation decision for inlined logical-expression chains), and no hunk in the report touches that code path — no corpus project contains a ?? [-style chain that exercises it.

@fisker
fisker merged commit 39888ab into prettier:main Oct 13, 2026
34 checks passed
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

2 participants