swiftlang/swift-format

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

Opened this issue · 1 comments

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 {}
+

rdar://132734611