Skip to content

Commit

Permalink
Enable explicit_init lint rule and fix issues (#3418)
Browse files Browse the repository at this point in the history
This rule will warn when calling `init` with the explicit type where it
can be inferred, or where the `.init` part can be omitted.
  • Loading branch information
MarkVillacampa committed Nov 15, 2023
1 parent 330e97c commit 679767a
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ opt_in_rules:
- multiline_parameters
- vertical_parameter_alignment
- vertical_parameter_alignment_on_call
- explicit_init

disabled_rules:
- orphaned_doc_comment
Expand Down
6 changes: 3 additions & 3 deletions Sources/Error Handling/ErrorUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -731,9 +731,9 @@ extension Error {

func addingUserInfo<Result: NSError>(_ userInfo: [String: Any]) -> Result {
let nsError = self as NSError
return Result.init(domain: nsError.domain,
code: nsError.code,
userInfo: nsError.userInfo + userInfo)
return .init(domain: nsError.domain,
code: nsError.code,
userInfo: nsError.userInfo + userInfo)
}

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Misc/Codable/IgnoreHashable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension IgnoreHashable: Hashable {
extension IgnoreHashable: Decodable where Value: Decodable {

init(from decoder: Decoder) throws {
self.init(wrappedValue: try Value.init(from: decoder))
self.init(wrappedValue: try .init(from: decoder))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private extension StoreProductDiscount.PaymentMode {
case .freeTrial:
self = .freeTrial
@unknown default:
Logger.appleWarning(Strings.storeKit.skunknown_payment_mode(String.init(describing: paymentMode)))
Logger.appleWarning(Strings.storeKit.skunknown_payment_mode(.init(describing: paymentMode)))
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private extension StoreProductDiscount.PaymentMode {
case .freeTrial:
self = .freeTrial
default:
Logger.appleWarning(Strings.storeKit.skunknown_payment_mode(String.init(describing: paymentMode)))
Logger.appleWarning(Strings.storeKit.skunknown_payment_mode(.init(describing: paymentMode)))
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func checkPaywallEventCreationData(_ creationData: PaywallEvent.CreationData) {
id: PaywallEvent.ID,
date: Date
) {
_ = PaywallEvent.CreationData.init(
_ = PaywallEvent.CreationData(
id: id,
date: date
)
Expand All @@ -240,7 +240,7 @@ func checkPaywallEventData(_ data: PaywallEvent.Data) {
locale: Locale,
darkMode: Bool
) {
_ = PaywallEvent.Data.init(
_ = PaywallEvent.Data(
offering: offering,
paywall: paywall,
sessionID: sessionID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BackendGetIntroEligibilityTests: BaseBackendTests {
let eligibility: [String: IntroEligibility]? = waitUntilValue { completed in
let products: Set<String> = ["producta", "productb", "productc"]
self.offerings.getIntroEligibility(appUserID: Self.userID,
receiptData: Data.init(1...2),
receiptData: .init(1...2),
productIdentifiers: products,
completion: {(productEligibility, error) in
expect(error).to(beNil())
Expand All @@ -97,7 +97,7 @@ class BackendGetIntroEligibilityTests: BaseBackendTests {
let products: Set<String> = ["producta"]
var eventualError: BackendError?
self.backend.offerings.getIntroEligibility(appUserID: "",
receiptData: Data.init(1...2),
receiptData: .init(1...2),
productIdentifiers: products,
completion: {(productEligibility, error) in
eventualError = error
Expand All @@ -112,7 +112,7 @@ class BackendGetIntroEligibilityTests: BaseBackendTests {
eventualError = nil

self.offerings.getIntroEligibility(appUserID: " ",
receiptData: Data.init(1...2),
receiptData: .init(1...2),
productIdentifiers: products,
completion: {(productEligibility, error) in
eventualError = error
Expand All @@ -136,7 +136,7 @@ class BackendGetIntroEligibilityTests: BaseBackendTests {
let eligibility: [String: IntroEligibility]? = waitUntilValue { completed in

self.offerings.getIntroEligibility(appUserID: Self.userID,
receiptData: Data.init(1...2),
receiptData: .init(1...2),
productIdentifiers: products,
completion: { productEligbility, error in
expect(error).to(beNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ class PurchasesPurchasingTests: BasePurchasesTests {
}

let transaction = MockTransaction()
transaction.mockPayment = SKPayment.init(product: otherProduct)
transaction.mockPayment = .init(product: otherProduct)

self.backend.postReceiptResult = .success(try CustomerInfo(data: Self.emptyCustomerInfoData))

Expand Down
12 changes: 6 additions & 6 deletions Tests/UnitTests/Purchasing/StoreKit1WrapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ class StoreKit1WrapperTests: TestCase, StoreKit1WrapperDelegate {
}

func testAddsPaymentsToTheQueue() {
let payment = SKPayment.init(product: SK1Product())
let payment = SKPayment(product: SK1Product())

wrapper?.add(payment)

expect(self.paymentQueue.addedPayments).to(contain(payment))
}

func testCallsDelegateWhenTransactionsAreUpdated() {
let payment = SKPayment.init(product: SK1Product())
let payment = SKPayment(product: SK1Product())
wrapper?.add(payment)

let transaction = MockTransaction()
Expand Down Expand Up @@ -134,10 +134,10 @@ class StoreKit1WrapperTests: TestCase, StoreKit1WrapperDelegate {
#endif

func testCallsDelegateOncePerTransaction() {
let payment1 = SKPayment.init(product: SK1Product())
let payment1 = SKPayment(product: SK1Product())
wrapper?.add(payment1)

let payment2 = SKPayment.init(product: SK1Product())
let payment2 = SKPayment(product: SK1Product())
wrapper?.add(payment2)

let transaction1 = MockTransaction()
Expand Down Expand Up @@ -203,9 +203,9 @@ class StoreKit1WrapperTests: TestCase, StoreKit1WrapperDelegate {

func testCallsRemovedTransactionDelegateMethod() {
let transaction1 = MockTransaction()
transaction1.mockPayment = SKPayment.init(product: SK1Product())
transaction1.mockPayment = SKPayment(product: SK1Product())
let transaction2 = MockTransaction()
transaction2.mockPayment = SKPayment.init(product: SK1Product())
transaction2.mockPayment = SKPayment(product: SK1Product())

wrapper?.paymentQueue(paymentQueue, removedTransactions: [transaction1, transaction2])

Expand Down

0 comments on commit 679767a

Please sign in to comment.