nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.66k stars 623 forks source link

Don't have implicit self for weak self captures, after self is unwrapped #1568

Open yagiztw opened 8 months ago

yagiztw commented 8 months ago

Implicit self is now permitted for weak self captures, after self is unwrapped. For example:

class ViewController {
  let button: Button

  func setup() {
      button.tapHandler = { [weak self] in
          guard let self else { return }
          dismiss() // refers to `self.dismiss()`
      }
  }

  func dismiss() { ... }
}

I looked into existing rules but couldn't find a rule that would allow us to force having explicit self. It would great if we have a rule for this.

nicklockwood commented 8 months ago

In general, the way to enable explicit self is --self insert, but I would not be surprised if it doesn't currently handle this case.