nicklockwood / SwiftFormat

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

conditionalAssignment rule #1538

Closed valeriachub closed 10 months ago

valeriachub commented 10 months ago

Hello developers, there are some issues with conditionalAssignment rule.

Version 0.52.6 / Swift 5.9

It reformats the following code:

let text: String
if conditionOne {
  text = "Hello World!"
  doSomeStuffHere()
} else {
   text = "Goodbye!"
}

to one with errors:

let text: String = if conditionOne {
  "Hello World!" // <---- Expression of type `String` is used
  doSomeStuffHere()
} else { // <---- Non-expression branch of `if` expression may only end with a `throw`
  "Goodbye!"
}

Could you please check?

Thank you!

nicklockwood commented 10 months ago

Cc @calda

calda commented 10 months ago

Will take a look

calda commented 10 months ago

Here you go: https://github.com/nicklockwood/SwiftFormat/pull/1539

nicklockwood commented 10 months ago

@valeriachub fixed in 0.52.7