nicklockwood / SwiftFormat

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

Add redundant typed throws rule #1718

Closed miguel-jimenez-0529 closed 3 weeks ago

miguel-jimenez-0529 commented 3 weeks ago

This PR adds a new redundantTypedThrows rule, which removes a typed throws (introduced in Swift 6.0) if it is redundant.

For example:

- func foo() throws(Never) -> Int {
+ func foo() -> Int {
      return 0
  }

- func foo() throws(any Error) -> Int {
+ func foo() throws -> Int {
      throw MyError.foo
  }

We don't remove (Error) because we can't guarantee it will reference the Swift.Error protocol (it's relatively common to define a custom error like enum Error: Swift.Error { ... }).

miguel-jimenez-0529 commented 3 weeks ago

cc: @calda

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.17%. Comparing base (56723db) to head (8b28de6).

Files Patch % Lines
Sources/Rules.swift 96.42% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1718 +/- ## =========================================== + Coverage 95.16% 95.17% +0.01% =========================================== Files 20 20 Lines 23185 23226 +41 =========================================== + Hits 22063 22105 +42 + Misses 1122 1121 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.