Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Add swiftlint and fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fsuc committed Jun 21, 2019
1 parent 091f4f5 commit 1270be5
Show file tree
Hide file tree
Showing 27 changed files with 150 additions and 122 deletions.
42 changes: 42 additions & 0 deletions .swiftlint.yml
@@ -0,0 +1,42 @@
opt_in_rules:
- closure_spacing
#- multiline_arguments # Disabled because of closures as arguments
- multiline_parameters
- let_var_whitespace
- operator_usage_whitespace
- literal_expression_end_indentation
- overridden_super_call
- prohibited_super_call
- redundant_nil_coalescing
- sorted_first_last
- sorted_imports
- switch_case_alignment
- unneeded_parentheses_in_closure_argument
- vertical_parameter_alignment_on_call
- yoda_condition

disabled_rules:
- line_length
- identifier_name

type_body_length:
warning: 500
error: 600

file_length:
warning: 800
error: 900

type_name:
max_length: 50

function_parameter_count:
warning: 7
error: 10

excluded:
- Pods
- build

trailing_whitespace:
ignores_empty_lines: true
18 changes: 18 additions & 0 deletions OCast.xcodeproj/project.pbxproj
Expand Up @@ -288,6 +288,7 @@
97AF813420EA0EAD00C502D5 /* Frameworks */,
97AF813520EA0EAD00C502D5 /* Headers */,
97AF813620EA0EAD00C502D5 /* Resources */,
9708176322BCD37200F73297 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -423,6 +424,23 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
9708176322BCD37200F73297 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\"\n";
};
97F35BFA20EBC1E200798238 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
18 changes: 9 additions & 9 deletions OCast/Core/DIALService.swift
Expand Up @@ -18,7 +18,7 @@

import Foundation

enum DIALError : Error {
enum DIALError: Error {
case httpRequest(HTTPRequestError)
case badContentResponse
}
Expand Down Expand Up @@ -57,7 +57,7 @@ class DIALService {
/// Get application info
///
/// - Parameter completion: result
public func info(ofApplication name: String, completion: @escaping (Result<DIALApplicationInfo, DIALError>) -> ()) {
public func info(ofApplication name: String, completion: @escaping (Result<DIALApplicationInfo, DIALError>) -> Void) {
HTTPRequest.launch(urlSession: urlSession, method: .GET, url: "\(baseURL)/\(name)") { result in
switch result {
case .failure(let httpError):
Expand Down Expand Up @@ -86,12 +86,12 @@ class DIALService {
/// Start the application
///
/// - Parameter completion: result
public func start(application name: String, completion: @escaping (Result<Void, DIALError>) -> ()) {
public func start(application name: String, completion: @escaping (Result<Void, DIALError>) -> Void) {
HTTPRequest.launch(urlSession: urlSession, method: .POST, url: "\(baseURL)/\(name)", successCode: 201) { result in
switch result {
case .failure(let httpError):
DispatchQueue.main.async { completion(.failure(.httpRequest(httpError))) }
case .success(_):
case .success:
DispatchQueue.main.async { completion(.success(())) }
}
}
Expand All @@ -100,18 +100,18 @@ class DIALService {
/// Stop the application
///
/// - Parameter completion: result
public func stop(application name: String, completion: @escaping (Result<Void, DIALError>) -> ()) {
info(ofApplication:name) { [weak self] result in
public func stop(application name: String, completion: @escaping (Result<Void, DIALError>) -> Void) {
info(ofApplication: name) { [weak self] result in
guard let `self` = self else { return }

switch result {
case .failure(let error):
completion(.failure(error))
case .success(let info):
var stopLink:String!
var stopLink: String!
if let runLink = info.runLink,
let url = URL(string: runLink),
let _ = url.host {
url.host != nil {
stopLink = runLink
} else if let runLink = URL(string: self.baseURL)?.appendingPathComponent(info.runLink ?? "run").absoluteString {
stopLink = runLink
Expand All @@ -123,7 +123,7 @@ class DIALService {
switch result {
case .failure(let httpError):
DispatchQueue.main.async { completion(.failure(.httpRequest(httpError))) }
case .success(_):
case .success:
DispatchQueue.main.async { completion(.success(())) }
}
})
Expand Down
6 changes: 3 additions & 3 deletions OCast/Core/Device.swift
Expand Up @@ -35,13 +35,13 @@ public enum DeviceState: Int {
}

/// The handler used to manage a result or an error.
public typealias ResultHandler<T> = (_ result: T?, _ error: Error?) -> ()
public typealias ResultHandler<T> = (_ result: T?, _ error: Error?) -> Void

/// The handler used to manage an error.
public typealias NoResultHandler = (_ error: Error?) -> ()
public typealias NoResultHandler = (_ error: Error?) -> Void

/// The event handler used to manage custom events.
public typealias EventHandler = (_ data: Data) -> ()
public typealias EventHandler = (_ data: Data) -> Void

/// The device representing the remote OCast device.
@objc
Expand Down
3 changes: 1 addition & 2 deletions OCast/Core/DeviceCenter.swift
Expand Up @@ -86,7 +86,7 @@ public class DeviceCenter: NSObject, DeviceDiscoveryDelegate {
/// The interval in seconds to refresh the devices. The minimum value is 5 seconds.
public var deviceDiscoveryInterval: UInt16 {
get { return deviceDiscovery?.interval ?? 0 }
set { deviceDiscovery?.interval = deviceDiscoveryInterval }
set { deviceDiscovery?.interval = newValue }
}

/// Registers a driver to discover devices of its manufacturer.
Expand Down Expand Up @@ -176,4 +176,3 @@ public class DeviceCenter: NSObject, DeviceDiscoveryDelegate {
userInfo: userInfo)
}
}

12 changes: 6 additions & 6 deletions OCast/Core/ReferenceDevice.swift
Expand Up @@ -22,7 +22,7 @@
import Foundation

/// The handler used to manage the command results.
internal typealias CommandResult = (Result<Data?, Error>) -> ()
internal typealias CommandResult = (Result<Data?, Error>) -> Void

/// The Reference device which conforms to the OCast specification.
@objc @objcMembers
Expand Down Expand Up @@ -195,7 +195,7 @@ open class ReferenceDevice: NSObject, Device, WebSocketDelegate {
guard let `self` = self else { return }

switch result {
case .success(_):
case .success:
Logger.shared.log(logLevel: .debug, "DIAL start request ended successfully")
// Do not wait on main thread
self.semaphoreQueue.async {
Expand Down Expand Up @@ -226,7 +226,7 @@ open class ReferenceDevice: NSObject, Device, WebSocketDelegate {

dialService.stop(application: applicationName) { result in
switch result {
case .success(_):
case .success:
Logger.shared.log(logLevel: .debug, "DIAL stop request ended successfully")
completion(nil)
case .failure(let error):
Expand Down Expand Up @@ -290,7 +290,7 @@ open class ReferenceDevice: NSObject, Device, WebSocketDelegate {
DispatchQueue.main.async {
guard let `self` = self else { return }
NotificationCenter.default.post(name: UpdateStatusEventNotification,
object: self, userInfo:[UpdateStatusUserInfoKey: updateStatus.message.data.params])
object: self, userInfo: [UpdateStatusUserInfoKey: updateStatus.message.data.params])
}
} else {
Logger.shared.log(logLevel: .error, "Can't decode updateStatus event")
Expand Down Expand Up @@ -338,7 +338,7 @@ open class ReferenceDevice: NSObject, Device, WebSocketDelegate {
/// - Parameters:
/// - jsonData: The JSON response.
/// - deviceLayer: The response device layer.
private func handleReply(from jsonData: Data, _ deviceLayer: OCastDeviceLayer<OCastDefaultResponseDataLayer>) {
private func handleReply(from jsonData: Data, _ deviceLayer: OCastDeviceLayer<OCastDefaultResponseDataLayer>) {
let commandHandler = commandHandlers[deviceLayer.id]
switch deviceLayer.status {
case .ok?:
Expand Down Expand Up @@ -484,7 +484,7 @@ open class ReferenceDevice: NSObject, Device, WebSocketDelegate {

self.state = .disconnected

self.commandHandlers.forEach { (_, completion) in
self.commandHandlers.forEach { _, completion in
completion(.failure(OCastError.deviceHasBeenDisconnected))
}
self.commandHandlers.removeAll()
Expand Down
2 changes: 1 addition & 1 deletion OCast/Core/WebSocket.swift
Expand Up @@ -115,7 +115,7 @@ class WebSocket: WebSocketProtocol, Starscream.WebSocketDelegate, Starscream.Web
socket.pongDelegate = self
}

// MARK - WebSocketProtocol properties & methods
// MARK: - WebSocketProtocol properties & methods

weak var delegate: WebSocketDelegate?

Expand Down
12 changes: 4 additions & 8 deletions OCast/DeviceDiscovery/UDPSocket.swift
Expand Up @@ -16,8 +16,8 @@
// limitations under the License.
//

import Foundation
import CocoaAsyncSocket
import Foundation

/// Protocol for responding to socket events.
protocol UDPSocketDelegate: class {
Expand Down Expand Up @@ -81,7 +81,7 @@ class UDPSocket: NSObject, UDPSocketProtocol, GCDAsyncUdpSocketDelegate {
udpSocket.synchronouslySetDelegateQueue(delegateQueue)
}

// MARK - UDPSocketProtocol properties & methods
// MARK: - UDPSocketProtocol properties & methods

weak var delegate: UDPSocketDelegate?

Expand All @@ -104,17 +104,13 @@ class UDPSocket: NSObject, UDPSocketProtocol, GCDAsyncUdpSocketDelegate {
udpSocket.send(payload, toHost: host, port: port, withTimeout: -1, tag: 0)
}

// MARK - GCDAsyncUdpSocketDelegate methods
// MARK: - GCDAsyncUdpSocketDelegate methods

func udpSocket(_ udpSocket : GCDAsyncUdpSocket, didReceive data: Data, fromAddress address: Data, withFilterContext _: Any?) {
func udpSocket(_ udpSocket: GCDAsyncUdpSocket, didReceive data: Data, fromAddress address: Data, withFilterContext _: Any?) {
delegate?.udpSocket(self, didReceive: data, fromHost: GCDAsyncSocket.host(fromAddress: address))
}

func udpSocketDidClose(_ sock: GCDAsyncUdpSocket, withError error: Error?) {
delegate?.udpSocketDidClose(self, with: error)
}
}




12 changes: 6 additions & 6 deletions OCast/DeviceDiscovery/UPNPService.swift
Expand Up @@ -119,12 +119,12 @@ class UPNPService: UPNPServiceProtocol {
let UDN = xmlDeviceElement["UDN"]?.value else { return nil }

return UPNPDevice(baseURL: applicationURL,
ipAddress: ipAddress,
servicePort: UInt16(applicationURL.port ?? 80),
deviceID: UPNPService.extractUUID(from: UDN) ?? UDN,
friendlyName: friendlyName,
manufacturer: manufacturer,
modelName: modelName)
ipAddress: ipAddress,
servicePort: UInt16(applicationURL.port ?? 80),
deviceID: UPNPService.extractUUID(from: UDN) ?? UDN,
friendlyName: friendlyName,
manufacturer: manufacturer,
modelName: modelName)
}

/// Returns the application URL from an HTTP response.
Expand Down
5 changes: 2 additions & 3 deletions OCast/Model/OCastGeneral.swift
Expand Up @@ -82,8 +82,7 @@ public typealias OCastMessage = NSObject & Codable
/// - browser: Browser.
/// - settings: Settings.
public enum OCastDomainName: String {
case browser = "browser"
case settings = "settings"
case browser, settings
}

/// The device layer message type.
Expand Down Expand Up @@ -150,7 +149,7 @@ class OCastDeviceLayer<T: Codable>: OCastMessage {
/// The message
public let message: OCastApplicationLayer<T>

private enum CodingKeys : String, CodingKey {
private enum CodingKeys: String, CodingKey {
case source = "src", destination = "dst", id, status, type, message
}

Expand Down
10 changes: 5 additions & 5 deletions OCast/Model/OCastMedia.swift
Expand Up @@ -58,7 +58,7 @@ public enum MediaType: Int, RawRepresentable, Codable {
}

public init?(rawValue: RawValue) {
switch (rawValue) {
switch rawValue {
case "audio": self = .audio
case "video": self = .video
case "image": self = .image
Expand Down Expand Up @@ -89,7 +89,7 @@ public enum MediaTrackType: Int, RawRepresentable, Codable {
}

public init?(rawValue: RawValue) {
switch (rawValue) {
switch rawValue {
case "audio": self = .audio
case "video": self = .video
case "text": self = .subtitle
Expand Down Expand Up @@ -117,7 +117,7 @@ public enum MediaTransferMode: Int, RawRepresentable, Codable {
}

public init?(rawValue: RawValue) {
switch (rawValue) {
switch rawValue {
case "buffered": self = .buffered
case "streamed": self = .streamed
default: return nil
Expand Down Expand Up @@ -177,7 +177,7 @@ public class MediaPlaybackStatus: OCastMessage {
/// The media duration in seconds.
public var duration: Double { return _duration ?? 0.0 }

enum CodingKeys : String, CodingKey {
enum CodingKeys: String, CodingKey {
case _volume = "volume", _mute = "mute", state = "state", _position = "position", _duration = "duration"
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public class MediaMetadata: OCastMessage {
/// The video tracks. See `MediaTrack`.
public let videoTracks: [MediaTrack]

enum CodingKeys : String, CodingKey {
enum CodingKeys: String, CodingKey {
case title = "title", subtitle = "subtitle", logo = "logo", _mediaType = "mediaType", subtitleTracks = "textTracks", audioTracks = "audioTracks", videoTracks = "videoTracks"
}
}
Expand Down
6 changes: 3 additions & 3 deletions OCast/Model/OCastSettings.swift
Expand Up @@ -50,7 +50,7 @@ public enum UpdateStatusState: Int, RawRepresentable, Codable {
public typealias RawValue = String

public var rawValue: RawValue {
switch (self) {
switch self {
case .notChecked: return "notChecked"
case .upToDate: return "upToDate"
case .newVersionFound: return "newVersionFound"
Expand All @@ -62,7 +62,7 @@ public enum UpdateStatusState: Int, RawRepresentable, Codable {
}

public init?(rawValue: RawValue) {
switch (rawValue) {
switch rawValue {
case "notChecked": self = .notChecked
case "upToDate": self = .upToDate
case "newVersionFound": self = .newVersionFound
Expand Down Expand Up @@ -107,7 +107,7 @@ public class InputGamepadAxes: OCastMessage {
/// The y axis (-1.0 -> 1.0).
public let y: Float

public let num : Int
public let num: Int
}

// MARK: - Settings Commands
Expand Down

0 comments on commit 1270be5

Please sign in to comment.