Skip to content

Move open group token past ifstmt's if token to avoid extra newlines. #191

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

Merged
merged 1 commit into from
Apr 16, 2020

Conversation

dylansturg
Copy link
Contributor

The implementation of consistent groups forces breaking inside of the group if the group starts at the beginning of a line (i.e. was immediately preceded by a break that fired). That isn't exactly what we want for if-stmt because the stmt generally starts at the beginning of a line and we want the breaks to fire only if the group is longer than the rest of the line.

Moving the open token past the if syntax token resolves 2 known complexities with consistent groups:

  1. Whether an immediately preceding break fired influences
  2. The spaceRemaining value is only updated after printing the first syntax token on a new line

It's a little odd to group in this way, since it logically makes more sense to group around the entire if-stmt but there aren't any breaks between the if token and the first condition so moving the open token doesn't change the length of any breaks throughout the statement.

The implementation of consistent groups forces breaking inside of the group if the group starts at the beginning of a line (i.e. was immediately preceded by a break that fired). That isn't exactly what we want for if-stmt because the stmt generally starts at the beginning of a line and we want the breaks to fire only if the group is longer than the rest of the line.

Moving the open token past the if `syntax` token resolves 2 known complexities with consistent groups:
1. Whether an immediately preceding break fired influences
2. The `spaceRemaining` value is only updated after printing the first `syntax` token on a new line

It's a little odd to group in this way, since it logically makes more sense to group around the entire if-stmt but there aren't any breaks between the if token and the first condition so moving the open token doesn't change the length of any breaks throughout the statement.
@allevato allevato merged commit 52626da into swiftlang:master Apr 16, 2020
@dylansturg dylansturg deleted the aggressive_ifs branch July 31, 2020 20:25
aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
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.

2 participants