Skip to content

fix: Improve contextual spacing for if statements when ifStatement.sp… #727

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

…aceAround: true

When ifStatement.spaceAround is true, make sure the spaces around parens are right based on the context of where the paren lies.

The change is to only add the space if the open paren is not at the end of a line. We do that on the opening paren 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 paren, we add the space if we're not the first token on the line.

The impetus for this was the case where an opening paren for an if statement control block was the last character on a line, or a closing paren was the first. For example: (where lineWidth: 40)

if (
    somereallylongidentifier
        <= anotherreallylongidentifier
) {
}

The above case was getting formatted with an extra space at the end of the if statement line and an extra space at the start of the close paren line.

…aceAround: true

When ifStatement.spaceAround is true, make sure the spaces around parens are right based on the context of where the paren lies.

The change is to only add the space if the open paren is not at the end of a line. We do that on the opening paren 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 paren, we add the space if we're not the first token on the line.

The impetus for this was the case where an opening paren for an if statement control block was the last character on a line, or a closing paren was the first.
For example: (where lineWidth: 40)
```
if (
    somereallylongidentifier
        <= anotherreallylongidentifier
) {
}
```

The above case was getting formatted with an extra space at the end of the if statement line and an extra space at the start of the close paren line.
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