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 swiftlint #782

Merged
merged 2 commits into from
Aug 25, 2021
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
12 changes: 3 additions & 9 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ excluded:
- PublicSDKAPITester
- vendor
- scan_derived_data
disabled_rules:
- trailing_comma
- todo
- cyclomatic_complexity
- function_body_length
- identifier_name
- line_length

opt_in_rules:
- sorted_imports
# TODO: enable this rule after the swift migration is finished.
# - missing_docs
- missing_docs

identifier_name:
max_length:
warning: 60
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let package = Package(
],
products: [
.library(name: "Purchases",
targets: ["Purchases"]),
targets: ["Purchases"])
],
dependencies: [],
targets: resolveTargets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class FakeASIdentifierManager: NSObject {

}

// TODO: Test if Objc can be removed.
@objc(RCASIdentifierManagerProxy)
class ASIdentifierManagerProxy: NSObject {
@objc class ASIdentifierManagerProxy: NSObject {

static let mangledIdentifierClassName = "NFVqragvsvreZnantre"
static let mangledIdentifierPropertyName = "nqiregvfvatVqragvsvre"
Expand Down
4 changes: 1 addition & 3 deletions PurchasesCoreSwift/Attribution/AdClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class FakeAdClient: NSObject {

}

// TODO: Test if Objc can be removed.
@objc(RCAdClientProxy)
class AdClientProxy: NSObject {
@objc class AdClientProxy: NSObject {

private static let className = "ADClient"

Expand Down
3 changes: 2 additions & 1 deletion PurchasesCoreSwift/Attribution/AttributionFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ private extension AttributionFetcher {
let minimumOSVersionRequiringAuthorization = OperatingSystemVersion(majorVersion: 14,
minorVersion: 5,
patchVersion: 0)
let needsTrackingAuthorization = systemInfo.isOperatingSystemAtLeastVersion(minimumOSVersionRequiringAuthorization)
let needsTrackingAuthorization = systemInfo
.isOperatingSystemAtLeastVersion(minimumOSVersionRequiringAuthorization)

guard let trackingManagerProxy = attributionFactory.atTrackingProxy() else {
if needsTrackingAuthorization {
Expand Down
2 changes: 2 additions & 0 deletions PurchasesCoreSwift/Attribution/AttributionPoster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AttributionPoster {
self.subscriberAttributesManager = subscriberAttributesManager
}

// swiftlint:disable function_body_length
func post(attributionData data: [String: Any],
fromNetwork network: AttributionNetwork,
networkUserId: String?) {
Expand Down Expand Up @@ -100,6 +101,7 @@ class AttributionPoster {
}
}
}
// swiftlint:enable function_body_length

func postAppleSearchAdsAttributionIfNeeded() {
guard attributionFetcher.isAuthorizedToPostSearchAds else {
Expand Down
1 change: 0 additions & 1 deletion PurchasesCoreSwift/Attribution/TrackingManagerProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class FakeTrackingManager: NSObject {

}

// TODO: Test if Objc can be removed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet, but I have #779, #780, #781 all ready to test each one 😄

@objc class TrackingManagerProxy: NSObject {

static let mangledTrackingClassName = "NGGenpxvatZnantre"
Expand Down
8 changes: 4 additions & 4 deletions PurchasesCoreSwift/FoundationExtensions/Data+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation

extension NSData {

func rc_asString() -> String {
func asString() -> String {
var deviceTokenString = ""
self.enumerateBytes { bytes, byteRange, _ in
for index in stride(from: 0, to: byteRange.length, by: 1) {
Expand All @@ -32,12 +32,12 @@ extension NSData {

extension Data {

var rc_asString: String {
return (self as NSData).rc_asString()
var asString: String {
return (self as NSData).asString()
}

// Returns a string representing a fetch token.
var rc_asFetchToken: String {
var asFetchToken: String {
return self.base64EncodedString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ private struct ROT13 {

fileprivate static func string(_ string: String) -> String {
if ROT13.key.isEmpty {
for i in 0 ..< 26 {
ROT13.key[ROT13.uppercase[i]] = ROT13.uppercase[(i + 13) % 26]
ROT13.key[ROT13.lowercase[i]] = ROT13.lowercase[(i + 13) % 26]
for number in 0 ..< 26 {
ROT13.key[ROT13.uppercase[number]] = ROT13.uppercase[(number + 13) % 26]
ROT13.key[ROT13.lowercase[number]] = ROT13.lowercase[(number + 13) % 26]
}
}

Expand Down
15 changes: 8 additions & 7 deletions PurchasesCoreSwift/Networking/Backend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ class Backend {
subscriberAttributes subscriberAttributesByKey: SubscriberAttributeDict?,
completion: @escaping BackendPurchaserInfoResponseHandler) {
// swiftlint:enable function_parameter_count
let fetchToken = receiptData.rc_asFetchToken
let fetchToken = receiptData.asFetchToken
var body: [String: Any] = [
"fetch_token": fetchToken,
"app_user_id": appUserID,
"is_restore": isRestore,
"observer_mode": observerMode,
"observer_mode": observerMode
]

let cacheKey =
Expand Down Expand Up @@ -153,15 +153,15 @@ class Backend {
}
}

// swiftlint:disable function_parameter_count
// swiftlint:disable function_parameter_count function_body_length
func post(offerIdForSigning offerIdentifier: String,
productIdentifier: String,
subscriptionGroup: String,
receiptData: Data,
appUserID: String,
completion: @escaping OfferSigningResponseHandler) {
// swiftlint:enable function_parameter_count
let fetchToken = receiptData.rc_asFetchToken
// swiftlint:enable function_parameter_count function_body_length
let fetchToken = receiptData.asFetchToken

let requestBody: [String: Any] = ["app_user_id": appUserID,
"fetch_token": fetchToken,
Expand Down Expand Up @@ -365,7 +365,7 @@ class Backend {
return
}

let fetchToken = receiptData.rc_asFetchToken
let fetchToken = receiptData.asFetchToken
let path = "/subscribers/\(appUserID)/intro_eligibility"
let body: [String: Any] = ["product_identifiers": productIdentifiers,
"fetch_token": fetchToken]
Expand Down Expand Up @@ -437,7 +437,8 @@ private extension Backend {
if statusCode > HTTPStatusCodes.redirect.rawValue {
let backendCode = maybeNumberFromError(code: response?["code"])
let backendMessage = response?["message"] as? String
let responsError = ErrorUtils.backendError(withBackendCode: backendCode as NSNumber?, backendMessage: backendMessage)
let responsError = ErrorUtils.backendError(withBackendCode: backendCode as NSNumber?,
backendMessage: backendMessage)
completion(nil, false, ErrorUtils.networkError(withUnderlyingError: responsError))
return
}
Expand Down
18 changes: 12 additions & 6 deletions PurchasesCoreSwift/Networking/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private extension HTTPClient {
requestBody: maybeRequestBody,
authHeaders: authHeaders,
retried: retried,
completionHandler: maybeCompletionHandler)
completion: maybeCompletionHandler)
}

if serially {
Expand All @@ -120,9 +120,10 @@ private extension HTTPClient {
request: HTTPRequest,
data maybeData: Data?,
error maybeNetworkError: Error?,
completionHandler maybeCompletionHandler: ((Int, [String: Any]?, Error?) -> Void)?,
completion maybeCompletionHandler: ((Int, [String: Any]?, Error?) -> Void)?,
beginNextRequestWhenFinished: Bool,
retried: Bool) {
// swiftlint:enable function_parameter_count
operationDispatcher.dispatchOnHTTPSerialQueue { [self] in
self.threadUnsafeHandleResponse(urlResponse: maybeURLResponse,
request: request,
Expand All @@ -134,13 +135,15 @@ private extension HTTPClient {
}
}

// swiftlint:disable function_body_length function_parameter_count
func threadUnsafePerformRequest(_ httpMethod: String,
serially: Bool,
path: String,
requestBody maybeRequestBody: [String: Any]?,
authHeaders: [String: String],
retried: Bool,
completionHandler maybeCompletionHandler: ((Int, [String: Any]?, Error?) -> Void)?) {
completion maybeCompletionHandler: ((Int, [String: Any]?, Error?) -> Void)?) {
// swiftlint:enable function_body_length function_parameter_count
let requestHeaders = self.defaultHeaders.merging(authHeaders)

let maybeURLRequest = self.createRequest(httpMethod: httpMethod,
Expand Down Expand Up @@ -194,21 +197,22 @@ private extension HTTPClient {
request: request,
data: data,
error: error,
completionHandler: maybeCompletionHandler,
completion: maybeCompletionHandler,
beginNextRequestWhenFinished: serially,
retried: retried)
}
task.resume()
}

// swiftlint:disable function_parameter_count
// swiftlint:disable function_body_length function_parameter_count
func threadUnsafeHandleResponse(urlResponse maybeURLResponse: URLResponse?,
request: HTTPRequest,
data maybeData: Data?,
error maybeNetworkError: Error?,
completionHandler maybeCompletionHandler: ((Int, [String: Any]?, Error?) -> Void)?,
beginNextRequestWhenFinished: Bool,
retried: Bool) {
// swiftlint:enable function_body_length function_parameter_count
var shouldBeginNextRequestWhenFinished = beginNextRequestWhenFinished
var statusCode = HTTPStatusCodes.networkConnectTimeoutError.rawValue
var jsonObject: [String: Any]?
Expand Down Expand Up @@ -310,7 +314,9 @@ private extension HTTPClient {
do {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: requestBody)
} catch let error {
Logger.error(String(format: Strings.network.creating_json_error, requestBody, error.localizedDescription))
Logger.error(String(format: Strings.network.creating_json_error,
requestBody,
error.localizedDescription))
return nil
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions PurchasesCoreSwift/Public/EntitlementInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ import Foundation
"""
}

// swiftlint:disable cyclomatic_complexity
public override func isEqual(_ object: Any?) -> Bool {
// swiftlint:enable cyclomatic_complexity
guard let info = object as? EntitlementInfo else {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ import Foundation

extension BackendErrorCode {

// swiftlint:disable cyclomatic_complexity
func toPurchasesErrorCode() -> ErrorCode {

// swiftlint:enable cyclomatic_complexity
switch self {
case .invalidPlatform:
return .configurationError
Expand Down Expand Up @@ -85,7 +86,6 @@ extension BackendErrorCode {
@unknown default:
return .unknownError
}

}

}
Loading