Repository navigation
feat: add jsxExpressionContainer.preferSingleLine to keep the braces on their own lines when written that way - #892
Merged
Conversation
…n written that way
Adds `jsxExpressionContainer.preferSingleLine`. When it's `false`, a JSX
expression container (children and attribute values) with a newline between
its open brace and expression gets its braces on their own lines with the
expression indented between them. Only the newline after the open brace is
checked. The option falls back to the global `preferSingleLine` when that's
set and is otherwise `true`, which keeps the braces beside the expression
like before, so the default output doesn't change.
Multi-line JSX directly in a container no longer adds its own newlines when
the container already puts its braces on their own lines, which also fixes
blank lines and unstable output for multi-line JSX after a comment in a
container (ex. `{\n// comment\n<div>...</div>\n}`).
The schema's `importDeclaration.preferSingleLine` and
`exportDeclaration.preferSingleLine` now point at a new
`preferSingleLineDefaultTrue` definition because they also default to `true`
when the global `preferSingleLine` isn't set, rather than the shared
definition's `false`.
Closes #577
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.
Closes #577
Adds
jsxExpressionContainer.preferSingleLine. When it'sfalse, a JSX expression container (in children or an attribute value) that has a newline after its{keeps its braces on their own lines, with the expression indented between them:Without a newline after
{, the braces hug the expression as before. This is how objects and the otherpreferSingleLinenodes keep line breaks. Only the newline after{decides, so{\n cond ? a : b}also puts the}on its own line.Like
importDeclaration.preferSingleLineandexportDeclaration.preferSingleLine, it falls back to the globalpreferSingleLinewhen that's set and is otherwisetrue, so default output doesn't change. Withtrue, the braces hug even when the content spans multiple lines, as before.With
jsx.multiLineParens: always, a newline after{is ignored when the expression is JSX, since it's already wrapped in{(...)}.This also fixes multi-line JSX right after a comment in a container (
{\n// comment\n<span>...</span>\n}), which got blank lines around it and changed on a second format.Schema
The per-node
preferSingleLineproperties shared a definition that says the default isfalse, which was wrong forimportDeclaration.preferSingleLineandexportDeclaration.preferSingleLine. They and the new option now use apreferSingleLineDefaultTruedefinition.Tests
issue0577.txthas the issue's examples.JsxExpressionContainer_PreferSingleLine_False.txtcovers children, attributes, conditionals,&&, arrow functions, object literals, text siblings, nested containers, comments, and empty and spread containers._Default,_Trueand_Global_Falseshow the default is unchanged, the per-node value wins, and the fallback to the globalpreferSingleLine.spaceSurroundingExpression,jsx.multiLineParensalwaysandnever, anduseTabs.resolve_config.rscovers how the option resolves.In the regression corpus I use, nothing changed.