Skip to content

fix: Improve contextual spacing for JSX expression containers when js… #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AaronLieberman
Copy link

…xExpressionContainer.spaceSurroundingExpression: true

When jsxExpressionContainer.spaceSurroundingExpression is true, make sure the spaces around braces are right based on the context of where the brace lies.

The change is to only add the space if the open brace is not at the end of a line. We do that on the opening brace by adding a Signal::SpaceOrNewLine which allows the system to add the space if it needs to for purposes of word wrap, otherwise ommitting it. For the close brace, we add the space if we're not the first token on the line.

The impetus for this was the case where an opening brace within a JSX element was the last character on a line, or a closing brace was the first. For example:

	<OuterComponent
		inner={
			<InnerComponent
				item={ content }
				className={ styles.someClass }
				foo={ areallylongidentifier }
				bar={ anotherreallylongidentifier }
			/>
		}
	/>;

The above case was getting formatted with extra spaces around the braces for the "inner" attribute.

This fixes this case and similar ones, plus adds additional varied test cases to cover variations of this idea.

…xExpressionContainer.spaceSurroundingExpression: true

When jsxExpressionContainer.spaceSurroundingExpression is true, make sure the spaces around braces are right based on the context of where the brace lies.

The change is to only add the space if the open brace is not at the end of a line. We do that on the opening brace by adding a Signal::SpaceOrNewLine which allows the system to add the space if it needs to for purposes of word wrap, otherwise ommitting it. For the close brace, we add the space if we're not the first token on the line.

The impetus for this was the case where an opening brace within a JSX element was the last character on a line, or a closing brace was the first.
For example:
```
	<OuterComponent
		inner={
			<InnerComponent
				item={ content }
				className={ styles.someClass }
				foo={ areallylongidentifier }
				bar={ anotherreallylongidentifier }
			/>
		}
	/>;
```

The above case was getting formatted with extra spaces around the braces for the "inner" attribute.

This fixes this case and similar ones, plus adds additional varied test cases to cover variations of this idea.
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.

1 participant