swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.47k stars 227 forks source link

Adjust indentation when using multiple if-let expressions #740

Closed DevYeom closed 4 months ago

DevYeom commented 4 months ago

Tested on 510.1.0 with 2 spaces for indentation.

Input:

func test() {
  if let abc,
     let def
  {
    print("hello")
  }
}

Output:

func test() {
  if let abc,
    let def
  {
    print("hello")
  }
}

Input code was formatted using Re-Indent (⌃I) in Xcode. It appears that the default indentation rule was applied. How about adding a rule for adjusting the indentation of multiple if-let expressions?

ahoppen commented 4 months ago

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

allevato commented 4 months ago

We made a fairly conscious decision early on to keep all indentation sizes fixed, rather than offering context-based variant indentations.

It's something we could revisit in the future, but for now, this is by design, and I want to be deliberate about increasing the surface area of the formatter's configurability. Each new setting creates the potential for interactions with other settings, making it harder to reason about.

DevYeom commented 4 months ago

Thanks!