Skip to content

Commit

Permalink
refactor: re-enable lint rules (#30)
Browse files Browse the repository at this point in the history
* refactor: re-enable lint rules

* more linting

* add back lint rule

* nit swiftlint

* use SPM for 5.4 test

* update ci

* update ci
  • Loading branch information
cbaker6 authored Dec 10, 2022
1 parent 35a7fe9 commit 3fd62f4
Show file tree
Hide file tree
Showing 111 changed files with 724 additions and 666 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Use multiple cores
run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
- name: Build-Test
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(iOS\) -destination platform\=iOS\ Simulator,name\=iPhone\ 12\ Pro\ Max -derivedDataPath DerivedData -test-iterations 10 -retry-tests-on-failure clean test | xcpretty
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(iOS\) -destination platform\=iOS\ Simulator,name\=iPhone\ 12\ Pro\ Max -derivedDataPath DerivedData clean test | xcpretty
env:
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
- name: Prepare codecov
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Use multiple cores
run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
- name: Build-Test
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(macOS\) -destination platform\=macOS -derivedDataPath DerivedData -test-iterations 10 -retry-tests-on-failure clean test | xcpretty
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(macOS\) -destination platform\=macOS -derivedDataPath DerivedData clean test | xcpretty
env:
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
- name: Prepare codecov
Expand All @@ -84,8 +84,8 @@ jobs:
- uses: actions/checkout@v3
- name: Use multiple cores
run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
- name: Build
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(tvOS\) -destination platform\=tvOS\ Simulator,name\=Apple\ TV -derivedDataPath DerivedData -test-iterations 10 -retry-tests-on-failure clean test | xcpretty
- name: Build-Test
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(tvOS\) -destination platform\=tvOS\ Simulator,name\=Apple\ TV -derivedDataPath DerivedData clean test | xcpretty
env:
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
- name: Prepare codecov
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
security set-keychain-settings -lut 7200 temporary
- name: Use multiple cores
run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
- name: Build and Test
- name: Build-Test
run: swift test --enable-code-coverage -v
env:
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
Expand All @@ -157,14 +157,14 @@ jobs:
env:
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}

xcode-test-ios-5_4:
xcode-test-tvos-5_4:
timeout-minutes: 15
needs: xcode-build-watchos
runs-on: macos-11
steps:
- uses: actions/checkout@v3
- name: Build-Test
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(iOS\) -destination platform\=iOS\ Simulator,name\=iPhone\ 11 -derivedDataPath DerivedData clean test | xcpretty
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(tvOS\) -destination platform\=tvOS\ Simulator,name\=Apple\ TV -derivedDataPath DerivedData clean test | xcpretty
env:
DEVELOPER_DIR: ${{ env.CI_XCODE_OLDEST }}
- name: Prepare codecov
Expand Down
8 changes: 0 additions & 8 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
disabled_rules:
- large_tuple
- unused_optional_binding
- type_name
- file_length
- cyclomatic_complexity
- function_body_length
- type_body_length
- inclusive_language
- comment_spacing
- identifier_name
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Tests/ParseSwiftTests/ParseEncoderTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ subscription2.handleUnsubscribe { query in
ParseLiveQuery.client?.close()

//: To close all LiveQuery connections use:
//ParseLiveQuery.client?.closeAll()
// ParseLiveQuery.client?.closeAll()

//: Ping the LiveQuery server. This should produce an error
//: because LiveQuery is disconnected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ query2.find { result in
/*: Explain the previous query. Read the documentation note on `explain`
queries and use a type-erased wrapper such as AnyCodable.
*/
//let explain: AnyDecodable = try query8.firstExplain()
//print(explain)
// let explain: AnyDecodable = try query8.firstExplain()
// print(explain)

PlaygroundPage.current.finishExecution()
//: [Next](@next)
20 changes: 0 additions & 20 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,6 @@
912C9BD424D3011F009947C3 /* Sources */,
912C9BD524D3011F009947C3 /* Frameworks */,
912C9BD624D3011F009947C3 /* Resources */,
918CED61268A23A700CFDC83 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -2637,25 +2636,6 @@
shellPath = /bin/sh;
shellScript = "if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nexport PATH\n\nif which swiftlint >/dev/null; then\n swiftlint --fix && swiftlint --strict\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
918CED61268A23A700CFDC83 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint --strict\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
918CED62268A23E600CFDC83 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/API/API+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import FoundationNetworking

internal extension API {
// MARK: API.Command
// swiftlint:disable:next type_body_length
struct Command<T, U>: Encodable where T: ParseEncodable {
typealias ReturnType = U // swiftlint:disable:this nesting
let method: API.Method
Expand Down Expand Up @@ -249,7 +250,7 @@ internal extension API {
}
}
} else if let otherURL = self.otherURL {
//Non-parse servers do not receive any parse dedicated request info
// Non-parse servers do not receive any parse dedicated request info
var request = URLRequest(url: otherURL)
request.cachePolicy = requestCachePolicy(options: options)
URLSession.parse.downloadTask(with: request, mapper: mapper) { result in
Expand Down
1 change: 1 addition & 0 deletions Sources/ParseSwift/API/API+NonParseBodyCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ internal extension API.NonParseBodyCommand {

internal extension API.NonParseBodyCommand {
// MARK: Batch - Child Objects
// swiftlint:disable:next function_body_length
static func batch(objects: [ParseEncodable],
transaction: Bool,
objectsSavedBeforeThisOne: [String: PointerType]?,
Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/Coding/AnyDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct AnyDecodable: Decodable {
}
}

protocol _AnyDecodable {
protocol _AnyDecodable { // swiftlint:disable:this type_name
var value: Any { get }
init<T>(_ value: T?)
}
Expand Down Expand Up @@ -74,6 +74,7 @@ extension _AnyDecodable {
}

extension AnyDecodable: Equatable {
// swiftlint:disable:next cyclomatic_complexity
static func == (lhs: AnyDecodable, rhs: AnyDecodable) -> Bool {
switch (lhs.value, rhs.value) {
#if canImport(Foundation)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/Coding/AnyEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AnyEncodable: Encodable {
}

@usableFromInline
protocol _AnyEncodable {
protocol _AnyEncodable { // swiftlint:disable:this type_name

var value: Any { get }
init<T>(_ value: T?)
Expand Down Expand Up @@ -110,6 +110,7 @@ extension _AnyEncodable {
}

#if canImport(Foundation)
// swiftlint:disable:next cyclomatic_complexity
private func encode(nsnumber: NSNumber, into container: inout SingleValueEncodingContainer) throws {
switch Character(Unicode.Scalar(UInt8(nsnumber.objCType.pointee))) {
case "c", "C":
Expand Down
18 changes: 10 additions & 8 deletions Sources/ParseSwift/Coding/ParseEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Parse. All rights reserved.
//

//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
Expand All @@ -16,10 +16,12 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//

import Foundation

// swiftlint:disable type_name

/// A marker protocol used to determine whether a value is a `String`-keyed `Dictionary`
/// containing `Encodable` values (in which case it should be exempt from key conversion strategies).
///
Expand Down Expand Up @@ -1117,9 +1119,9 @@ internal struct _ParseEncodingStorage {
}
}

//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//
// Error Utilities
//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//

extension EncodingError {
/// Returns a `.invalidValue` error describing the given invalid floating-point value.
Expand All @@ -1143,9 +1145,9 @@ extension EncodingError {
}
}

//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//
// Shared Key Types
//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//

private struct _JSONKey : CodingKey {
public var stringValue: String
Expand Down Expand Up @@ -1174,9 +1176,9 @@ private struct _JSONKey : CodingKey {
static let `super` = _JSONKey(stringValue: "super")!
}

//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//
// Shared ISO8601 Date Formatter
//===----------------------------------------------------------------------===//
// ===----------------------------------------------------------------------===//
// swiftlint:disable:next line_length
// NOTE: This value is implicitly lazy and _must_ be lazy. We're compiled against the latest SDK (w/ ISO8601DateFormatter), but linked against whichever Foundation the user has. ISO8601DateFormatter might not exist, so we better not hit this code path on an older OS.
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/Extensions/URLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ internal extension URLSession {
return Int.random(in: 0 ..< Int(truncating: min))
}

// swiftlint:disable:next function_body_length cyclomatic_complexity
func makeResult<U>(request: URLRequest,
responseData: Data?,
urlResponse: URLResponse?,
Expand Down Expand Up @@ -217,7 +218,7 @@ internal extension URLSession {
}

internal extension URLSession {
func uploadTask<U>( // swiftlint:disable:this function_parameter_count
func uploadTask<U>( // swiftlint:disable:this function_body_length function_parameter_count
notificationQueue: DispatchQueue,
with request: URLRequest,
from data: Data?,
Expand Down
23 changes: 12 additions & 11 deletions Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class ParseLiveQuery: NSObject {
let synchronizationQueue: DispatchQueue
let notificationQueue: DispatchQueue

//Task
// Task
var task: URLSessionWebSocketTask! {
willSet {
if newValue == nil && isSocketEstablished {
Expand Down Expand Up @@ -108,7 +108,7 @@ Not attempting to open ParseLiveQuery socket anymore
public weak var receiveDelegate: ParseLiveQueryDelegate?

/// True if the connection to the url is up and available. False otherwise.
public internal(set) var isSocketEstablished = false { //URLSession has an established socket
public internal(set) var isSocketEstablished = false { // URLSession has an established socket
willSet {
if !newValue {
isConnected = newValue
Expand All @@ -125,7 +125,7 @@ Not attempting to open ParseLiveQuery socket anymore
if let task = self.task {
attempts = 1

//Resubscribe to all subscriptions by moving them in front of pending
// Resubscribe to all subscriptions by moving them in front of pending
var tempPendingSubscriptions = [(RequestId, SubscriptionRecord)]()
self.subscriptions.forEach { (key, value) -> Void in
tempPendingSubscriptions.append((key, value))
Expand All @@ -134,7 +134,7 @@ Not attempting to open ParseLiveQuery socket anymore
tempPendingSubscriptions.append(contentsOf: pendingSubscriptions)
pendingSubscriptions = tempPendingSubscriptions

//Send all pending messages in order
// Send all pending messages in order
self.pendingSubscriptions.forEach {
let messageToSend = $0
URLSession.liveQuery.send(messageToSend.1.messageData, task: task) { _ in }
Expand All @@ -161,7 +161,7 @@ Not attempting to open ParseLiveQuery socket anymore
}
}

//Subscription
// Subscription
let requestIdGenerator: () -> RequestId
var subscriptions = [RequestId: SubscriptionRecord]()
var pendingSubscriptions = [(RequestId, SubscriptionRecord)]() // Behave as FIFO to maintain sending order
Expand Down Expand Up @@ -348,28 +348,29 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
}
}

// swiftlint:disable:next function_body_length cyclomatic_complexity
func received(_ data: Data) {
synchronizationQueue.sync {
if let redirect = try? ParseCoding.jsonDecoder().decode(RedirectResponse.self, from: data) {
if redirect.op == .redirect {
self.url = redirect.url
if self.isConnected {
self.close(useDedicatedQueue: true)
//Try to reconnect
// Try to reconnect
self.resumeTask { _ in }
}
}
return
}

//Check if this is an error response
// Check if this is an error response
if let error = try? ParseCoding.jsonDecoder().decode(ErrorResponse.self, from: data) {
if !error.reconnect {
//Treat this as a user disconnect because the server does not want to hear from us anymore
// Treat this as a user disconnect because the server does not want to hear from us anymore
self.close()
}
guard let parseError = try? ParseCoding.jsonDecoder().decode(ParseError.self, from: data) else {
//Turn LiveQuery error into ParseError
// Turn LiveQuery error into ParseError
let parseError = ParseError(code: .otherCause,
// swiftlint:disable:next line_length
message: "ParseLiveQuery Error: code: \(error.code), message: \(error.message)")
Expand All @@ -383,10 +384,10 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
}
return
} else if !self.isConnected {
//Check if this is a connected response
// Check if this is a connected response
guard let response = try? ParseCoding.jsonDecoder().decode(ConnectionResponse.self, from: data),
response.op == .connected else {
//If not connected, should not receive anything other than a connection response
// If not connected, should not receive anything other than a connection response
guard let outOfOrderMessage = try? ParseCoding
.jsonDecoder()
.decode(AnyCodable.self, from: data) else {
Expand Down
1 change: 1 addition & 0 deletions Sources/ParseSwift/Objects/ParseInstallation+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ internal extension ParseInstallation {

// MARK: Batch Support
internal extension Sequence where Element: ParseInstallation {
// swiftlint:disable:next function_body_length
func batchCommand(method: Method,
batchLimit limit: Int?,
transaction: Bool,
Expand Down
Loading

0 comments on commit 3fd62f4

Please sign in to comment.