Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable explicit_init lint rule and fix issues #3418

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)))

Check warning on line 78 in Sources/Purchasing/StoreKitAbstractions/SK1StoreProductDiscount.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Purchasing/StoreKitAbstractions/SK1StoreProductDiscount.swift#L78

Added line #L78 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do

Suggested change
Logger.appleWarning(Strings.storeKit.skunknown_payment_mode(.init(describing: paymentMode)))
Logger.appleWarning(Strings.storeKit.skunknown_payment_mode(paymentMode.rawValue))

That doesn't use reflection so it's a lot faster

Copy link
Member Author

@MarkVillacampa MarkVillacampa Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly it's a UInt enum :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then String(enum.rawValue). Describing uses runtime reflection and it's A LOT slower.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already merged so it's fine. It was already like this anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's not like this is a hot path.

return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
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)))

Check warning on line 63 in Sources/Purchasing/StoreKitAbstractions/SK2StoreProductDiscount.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Purchasing/StoreKitAbstractions/SK2StoreProductDiscount.swift#L63

Added line #L63 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

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