nicklockwood / SwiftFormat

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

The redundantReturn rule is unexpectedly being applied below "// swiftformat:disable:next redundantReturn" #1509

Closed acosmicflamingo closed 1 year ago

acosmicflamingo commented 1 year ago

With the new SwiftFormat 0.52.1 release (was working in 0.52.0), I am noticing that applying swiftformat results in removing return from a line where the following precedes it: // swiftformat:disable:next redundantReturn. Has this rule been renamed?

Here's an example:

public func UIConfirmationDialogController<Action: Equatable>(
  state: UIAlertState<Action>,
  send: @escaping (Action?) -> Void
) -> UIAlertController {
  // swiftformat:disable:next redundantReturn
- return UIAlertController(state: state, send: send, preferredStyle: .actionSheet)
+ UIAlertController(state: state, send: send, preferredStyle: .actionSheet)
}
nicklockwood commented 1 year ago

@acosmicflamingo this seems to be a new bug. The rule name hasn't changed.

nicklockwood commented 1 year ago

@acosmicflamingo something like this should still work:

// swiftformat:disable redundantReturn
public func UIConfirmationDialogController<Action: Equatable>(
  state: UIAlertState<Action>,
  send: @escaping (Action?) -> Void
) -> UIAlertController {
  return UIAlertController(state: state, send: send, preferredStyle: .actionSheet)
}
// swiftformat:enable redundantReturn
acosmicflamingo commented 1 year ago

Fascinating. Your code snippet does work, but this does not:

public func UIConfirmationDialogController<Action: Equatable>(
  state: UIAlertState<Action>,
  send: @escaping (Action?) -> Void
) -> UIAlertController {
  // swiftformat:disable redundantReturn
  return UIAlertController(state: state, send: send, preferredStyle: .actionSheet)
  // swiftformat:enable redundantReturn
}

Is there anything you want me to run on my end that can help with debugging?

nicklockwood commented 1 year ago

@acosmicflamingo I just fixed it :-)

acosmicflamingo commented 1 year ago

@nicklockwood yay! Thanks a bunch :D

nicklockwood commented 1 year ago

@acosmicflamingo fix landed in 0.52.2