swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.49k stars 229 forks source link

`NoEmptyLinesOpeningClosingBraces` removes empty lines from body if functions start/end with comment #807

Open andre-richter opened 1 month ago

andre-richter commented 1 month ago

The following, when NoEmptyLinesOpeningClosingBraces is true,

func foo() {
  let x = 1

  // let y = 2
  // let z = 3
}

results in

func foo() {
  let x = 1
  // let y = 2
  // let z = 3
}

It also happens the other way around.

func foo() {
  // let w = 0

  let x = 1
}

becomes

func foo() {
  // let w = 0
  let x = 1
}

IMO both cases should be left unchanged, because these empty lines will likely be intentional. Also, in the stricter sense, they are not located after/before the opening/closing braces.

ahoppen commented 1 month ago

Synced to Apple’s issue tracker as rdar://136130930

allevato commented 1 month ago

@mateusrodriguesxyz Would you be able to take a look at this?