Skip to content
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

Fix postfix-#if formatting when they come after a closing parenthesis. #554

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

allevato
Copy link
Member

A previous change caused the following formatting, which is less than ideal:

SomeView(
  args
)
  #if os(iOS)
    .someModifier()
  #endif

In this case, the #if block should be at the same identation level as the closing parenthesis, similar to how we handle closing braces (}).

This change moves the treatment of breaks for postfix-#if out of the visitor for #if clauses and instead uses the same contextual break previsition we use for other member access expressions. The result handles more cases correctly, and is a simpler, less special-casey implementation.

A previous change caused the following formatting, which is less than ideal:

```swift
SomeView(
  args
)
  #if os(iOS)
    .someModifier()
  #endif
```

In this case, the `#if` block should be at the same identation level as the
closing parenthesis, similar to how we handle closing braces (`}`).

This change moves the treatment of breaks for postfix-`#if` out of the
visitor for `#if` clauses and instead uses the same contextual break
previsition we use for other member access expressions. The result handles
more cases correctly, and is a simpler, less special-casey implementation.
@allevato allevato merged commit 464850a into swiftlang:main Jun 28, 2023
@allevato allevato deleted the poundif-after-paren branch June 28, 2023 20:22
allevato added a commit to allevato/swift-format that referenced this pull request Jun 29, 2023
Fix postfix-`#if` formatting when they come after a closing parenthesis.
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