nicklockwood / SwiftFormat

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

Fix more edge cases related to if/switch expressions #1561

Closed calda closed 11 months ago

calda commented 11 months ago

This PR fixes two issues where SwiftFormat would convert code to use if/switch expressions that did not compile:

  1. If / switch expressions are not permitted in method calls, like:
XCTAssert(if condition {
  foo
} else {
  bar
}
  1. Due to this issue in Swift 5.9 (fixed in 5.10), as? operators are not supported in if/switch expressions. This example does not compile in Swift 5.9:
let result: String? = if condition {
  foo as? String
} else {
  "bar"
}
codecov[bot] commented 11 months ago

Codecov Report

Merging #1561 (0c24a70) into develop (0116632) will increase coverage by 0.01%. The diff coverage is 97.56%.

@@             Coverage Diff             @@
##           develop    #1561      +/-   ##
===========================================
+ Coverage    95.01%   95.03%   +0.01%     
===========================================
  Files           20       20              
  Lines        21743    21819      +76     
===========================================
+ Hits         20660    20736      +76     
  Misses        1083     1083              
Files Coverage Δ
Sources/FormattingHelpers.swift 97.70% <100.00%> (+0.02%) :arrow_up:
Sources/SwiftFormat.swift 87.70% <ø> (ø)
Sources/Rules.swift 98.51% <96.00%> (-0.02%) :arrow_down:

... and 1 file with indirect coverage changes

nicklockwood commented 11 months ago

Thanks!