nicklockwood / SwiftFormat

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

Update `redundantClosure` rule to preserve closure where if/switch expression would not be allowed #1553

Closed calda closed 9 months ago

calda commented 9 months ago

This PR updates the redundantClosure rule to preserve closures with if/switch expressions if the closure is in a position where an if/switch expression would not be allowed. In Swift 5.9 if/switch expressions are only allowed as either return values, or as the result of an assignment.

This PR also fixes miscellaneous issues where redundantClosure didn't properly handle some combinations of explicit return, try/await, and if/switch expressions.

Fixes #1547 and #1548.

codecov[bot] commented 9 months ago

Codecov Report

Merging #1553 (3f34cf8) into develop (e3ec9af) will increase coverage by 0.02%. The diff coverage is 97.80%.

@@             Coverage Diff             @@
##           develop    #1553      +/-   ##
===========================================
+ Coverage    94.96%   94.98%   +0.02%     
===========================================
  Files           20       20              
  Lines        21670    21738      +68     
===========================================
+ Hits         20578    20648      +70     
+ Misses        1092     1090       -2     
Files Coverage Δ
Sources/ParsingHelpers.swift 96.60% <100.00%> (-0.01%) :arrow_down:
Sources/FormattingHelpers.swift 97.68% <97.22%> (+0.01%) :arrow_up:
Sources/Rules.swift 98.53% <98.14%> (-0.01%) :arrow_down:

... and 1 file with indirect coverage changes

nicklockwood commented 9 months ago

Thanks so much Cal ❤️

calda commented 9 months ago

Happy to heelllppp