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

Existing line breaks between attributes are not removed respectsExistingLineBreaks == false #786

Open
dduan opened this issue Jul 29, 2024 · 1 comment

Comments

@dduan
Copy link
Contributor

dduan commented Jul 29, 2024

Summary:

When respectsExistingLineBreaks is set to false, existing line breaks between adjacent attributes, which are redundant, are preserved. Ideally, they should be removed.

Steps To Reproduce:

Run the following unit test in swift-format

  func testLineBreaksBetweenAttributesAreRemovedWhenNecessary() {
    let input =
      """
      @available(iOS 16.0, *) @available(macOS 14.0, *)

      @available(tvOS 16.0, *)

      @frozen
      struct X {}
      """

    let expected =
      """
      @available(iOS 16.0, *) @available(macOS 14.0, *) @available(tvOS 16.0, *)
      @frozen
      struct X {}

      """
    var configuration = Configuration.forTesting
    configuration.respectsExistingLineBreaks = false
    assertPrettyPrintEqual(input: input, expected: expected, linelength: 80, configuration: configuration)
  }

diagnostics for failure:

failed - Pretty-printed result was not what was expected - Actual output (+) differed from expected output (-):
-@available(iOS 16.0, *) @available(macOS 14.0, *) @available(tvOS 16.0, *)
-@frozen
-struct X {}
+@available(iOS 16.0, *) @available(macOS 14.0, *)
 
+@available(tvOS 16.0, *)
+
+@frozen struct X {}
+
@dduan
Copy link
Contributor Author

dduan commented Jul 29, 2024

rdar://132734611

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

No branches or pull requests

1 participant