nicklockwood / SwiftFormat

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

[#1525] Fix issue where removing return from failable init would break build #1532

Closed calda closed 11 months ago

calda commented 11 months ago

This PR fixes #1525, where the redundant return rule would unexpectedly remove the return keyword from a conditional statement in a failable init, where explicit return is required.

Before

init?(optionalHex: String?) {
    if let optionalHex {
        self.init(hex: optionalHex)
    } else {
-        return nil
+        nil
    }
}

After

init?(optionalHex: String?) {
    if let optionalHex {
        self.init(hex: optionalHex)
    } else {
        return nil
    }
}
codecov[bot] commented 11 months ago

Codecov Report

Merging #1532 (5e11ab2) into develop (d03974d) will increase coverage by 0.02%. The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1532      +/-   ##
===========================================
+ Coverage    94.99%   95.02%   +0.02%     
===========================================
  Files           20       20              
  Lines        21448    21457       +9     
===========================================
+ Hits         20375    20389      +14     
+ Misses        1073     1068       -5     
Files Coverage Δ
Sources/Rules.swift 98.63% <100.00%> (+<0.01%) :arrow_up:

... and 2 files with indirect coverage changes

nicklockwood commented 11 months ago

Looks good, thanks!