nicklockwood / SwiftFormat

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

`redundantReturn` Rule Bug #1513

Closed userNameIsBoris closed 11 months ago

userNameIsBoris commented 1 year ago

Hi!

Thanks for the SwiftFormat, guys! The tool is cool, but today i ran into a bug. redundantReturn rule deletes return statement unexpectedly when it's following by a switch-case statement. Check this out please :)

Video example:

https://github.com/nicklockwood/SwiftFormat/assets/68778381/98a413af-66c5-4034-9d60-a07e12ecaaa9

Code example:

enum DeveloperLifeCycle {
  case eating
  case sleeping
  case coding
}

func swiftFormatBug() -> DeveloperLifeCycle {
  // And we want to hardcode a value for a test...
  return .coding

  // Suppose we have switch-case with return statement inside...
  let state = DeveloperLifeCycle.coding

  switch state {
  case .eating, .sleeping, .coding:
    return state
  }
}
nicklockwood commented 11 months ago

@userNameIsBoris fixed in 0.52.3

userNameIsBoris commented 11 months ago

@nicklockwood Great news! Thanks a lot!