Fix extra indentation for inline array/object in logical chains - #19792
Open
santhiprakash wants to merge 2 commits into
Open
Fix extra indentation for inline array/object in logical chains#19792santhiprakash wants to merge 2 commits into
santhiprakash wants to merge 2 commits into
Conversation
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
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
printBinaryishExpressiondetermined it should use the chain layout, it wrapped the whole tail inindent(), which compounded with the array/object's own indentation. The newisInlineLogicalExpressionhelper checks whether the entire flattened chain consists of inline right-hand operands; if so, the outerindent()is skipped and the array/object contents align with the surrounding expression instead of being shifted one extra level.Fixes #5183
Checklist
changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.