Skip to content

fix: don't add a space between a jsx expression container's braces and an object or array literal - #882

Merged
dsherret merged 1 commit into
mainfrom
fix-jsx-expr-container-object-space
Nov 4, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix-jsx-expr-container-object-space

Conversation

@dsherret

@dsherret dsherret commented Nov 4, 2026

Copy link
Copy Markdown
Member

Closes #602

With jsxExpressionContainer.spaceSurroundingExpression: true, an object or array literal got spaces between its braces and the container's braces:

<div style={ { value: true } } myProp={ [{ value: true }] } />

There's now no space next to an object or array literal, like eslint's react/jsx-curly-spacing with objectLiterals: "never":

<div style={{ value: true }} myProp={[{ value: true }]} />
  • This also applies to multi-line literals (style={{ ... }}), empty literals and literal children.
  • Parens that get removed are looked through, so {({ a: 1 })} is stable.
  • A comment beside the literal keeps the space ({ /* c */ { a: 1 } }), as do other expressions (ex. { { a: 1 } as T } or { [1].map(f) }) and spread attributes.

This only changes output when the option is enabled.

Tests

  • issue0602.txt has the issue's examples, empty literals, children, removed and kept parens, comments, and multi-line literals.
  • The "open braces followed by open braces" case in JsxExpressionContainer_SpaceSurroundingExpression_True.txt now expects style={{ instead of style={ {.

@dsherret
dsherret merged commit 6bd52f5 into main Nov 4, 2026
1 check passed
@dsherret
dsherret deleted the fix-jsx-expr-container-object-space branch November 4, 2026 22:24
thristhart added a commit to thristhart/dprint-plugin-typescript that referenced this pull request Nov 6, 2026
dprint#882 stopped adding a space between a JSX expression container's braces
and an object or array literal (`style={{ color }}`). That's a good
default, but some codebases enforce `style={ { color } }` with eslint's
`react/jsx-curly-spacing` (`when: always`, which doesn't allow `{{` by
default) and have no way to keep it.

This adds `jsxExpressionContainer.spaceSurroundingObjectOrArrayLiteral`
(default `false`, which keeps the current output) for the space around
an object or array literal. It's independent of
`jsxExpressionContainer.spaceSurroundingExpression`, which is now used
for every other expression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thristhart added a commit to thristhart/dprint-plugin-typescript that referenced this pull request Nov 6, 2026
this option brings back the behavior fixed by dprint#882 (as mentioned in dprint#602)
dsherret added a commit to thristhart/dprint-plugin-typescript that referenced this pull request Nov 6, 2026
…eral and spaceSurroundingArrayLiteral

Both default to the value of `jsxExpressionContainer.spaceSurroundingExpression`, which restores the output from before dprint#882. Set them to `false` to keep the brackets beside the braces (ex. `{{ value: true }}`).
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.

Option jsxExpressionContainer.spaceSurroundingExpression adds spaces between multiple braces

1 participant