diff --git a/.swiftlint.yml b/.swiftlint.yml index 6f767d9..5e55a24 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,5 +1,8 @@ disabled_rules: + - function_body_length - identifier_name + - line_length + - todo - trailing_whitespace - type_name - vertical_whitespace diff --git a/Sources/SwiftKit/Authentication/AuthenticationService.swift b/Sources/SwiftKit/Authentication/AuthenticationService.swift index 7b8deed..5a2da95 100644 --- a/Sources/SwiftKit/Authentication/AuthenticationService.swift +++ b/Sources/SwiftKit/Authentication/AuthenticationService.swift @@ -14,7 +14,7 @@ import Foundation */ public protocol AuthenticationService: AnyObject { - typealias AuthCompletion = (_ result: AuthResult) -> () + typealias AuthCompletion = (_ result: AuthResult) -> Void typealias AuthError = AuthenticationServiceError typealias AuthResult = Result diff --git a/Sources/SwiftKit/Data/StandardCsvParser.swift b/Sources/SwiftKit/Data/StandardCsvParser.swift index 41394c5..55cc304 100644 --- a/Sources/SwiftKit/Data/StandardCsvParser.swift +++ b/Sources/SwiftKit/Data/StandardCsvParser.swift @@ -12,13 +12,19 @@ public class StandardCsvParser: CsvParser { public init() {} - public func parseCvsString(_ string: String, separator: Character) -> [[String]] { + public func parseCvsString( + _ string: String, + separator: Character) -> [[String]] { let allRows = string.components(separatedBy: .newlines) let rows = allRows.filter { $0.trimmingCharacters(in: .whitespaces).count > 0 } return rows.map { $0.split(separator: separator).map { String($0) } } } - public func parseCvsFile(named fileName: String, withExtension ext: String, in bundle: Bundle, separator: Character) throws -> [[String]] { + public func parseCvsFile( + named fileName: String, + withExtension ext: String, + in bundle: Bundle, + separator: Character) throws -> [[String]] { let url = bundle.url(forResource: fileName, withExtension: ext) guard let fileUrl = url else { throw CsvParserError.noSuchFile(fileName, fileExtension: ext) } let data = try Data(contentsOf: fileUrl) diff --git a/Sources/SwiftKit/Date/Date+Difference.swift b/Sources/SwiftKit/Date/Date+Difference.swift index e98a296..b713078 100644 --- a/Sources/SwiftKit/Date/Date+Difference.swift +++ b/Sources/SwiftKit/Date/Date+Difference.swift @@ -38,4 +38,3 @@ public extension Date { calendar.dateComponents([.second], from: date, to: self).second ?? 0 } } - diff --git a/Sources/SwiftKit/Date/DateEncoders.swift b/Sources/SwiftKit/Date/DateEncoders.swift index eccdc72..7c76d50 100644 --- a/Sources/SwiftKit/Date/DateEncoders.swift +++ b/Sources/SwiftKit/Date/DateEncoders.swift @@ -23,7 +23,7 @@ public extension JSONEncoder { private extension JSONEncoder.DateEncodingStrategy { - static let customISO8601 = custom { (date, encoder) throws -> () in + static let customISO8601 = custom { (date, encoder) throws -> Void in let formatter = DateFormatter.iso8601Milliseconds let string = formatter.string(from: date) var container = encoder.singleValueContainer() diff --git a/Sources/SwiftKit/Files/BundleFileFinder.swift b/Sources/SwiftKit/Files/BundleFileFinder.swift index f98dcda..f6978e7 100644 --- a/Sources/SwiftKit/Files/BundleFileFinder.swift +++ b/Sources/SwiftKit/Files/BundleFileFinder.swift @@ -33,7 +33,7 @@ private extension BundleFileFinder { let files = try fileManager.contentsOfDirectory(atPath: path) let array = files as NSArray let filteredFiles = array.filtered(using: predicate) - return filteredFiles as! [String] + return filteredFiles as? [String] ?? [] } catch { return [String]() } diff --git a/Sources/SwiftKit/Localization/StandardLocalizationService.swift b/Sources/SwiftKit/Localization/StandardLocalizationService.swift index ee81164..e8a86f3 100644 --- a/Sources/SwiftKit/Localization/StandardLocalizationService.swift +++ b/Sources/SwiftKit/Localization/StandardLocalizationService.swift @@ -17,8 +17,6 @@ import Foundation but as soon as you call `setLocale` the standard translator will replaced with a `BundleTranslator`, that will used the bundle of the new locale. - - `TODO` Write unit tests with mocked types for this service. */ open class StandardLocalizationService: LocalizationService { diff --git a/Tests/SwiftKitTests/Authentication/BiometricAuthenticationServiceTests.swift b/Tests/SwiftKitTests/Authentication/BiometricAuthenticationServiceTests.swift index 2e16eb8..e0ef568 100644 --- a/Tests/SwiftKitTests/Authentication/BiometricAuthenticationServiceTests.swift +++ b/Tests/SwiftKitTests/Authentication/BiometricAuthenticationServiceTests.swift @@ -103,7 +103,10 @@ private class TestClass: BiometricAuthenticationService, Mockable { invoke(canAuthenticateUserRef, args: (auth)) } - override func performAuthentication(for auth: Authentication, reason: String, completion: @escaping BiometricAuthenticationService.AuthCompletion) { + override func performAuthentication( + for auth: Authentication, + reason: String, + completion: @escaping AuthCompletion) { invoke(performAuthenticationRef, args: (auth, reason, completion)) if let error = authError { return completion(.failure(error)) } completion(.success(())) diff --git a/Tests/SwiftKitTests/Authentication/CachedAuthenticationServiceProxyTests.swift b/Tests/SwiftKitTests/Authentication/CachedAuthenticationServiceProxyTests.swift index b2f6774..9b9d024 100644 --- a/Tests/SwiftKitTests/Authentication/CachedAuthenticationServiceProxyTests.swift +++ b/Tests/SwiftKitTests/Authentication/CachedAuthenticationServiceProxyTests.swift @@ -84,21 +84,21 @@ class CachedAuthenticationServiceProxyTests: QuickSpec { it("is false after a failed authentication") { mock.authError = TestError.failure - service.authenticateUser(for: .standard, reason: "") { result in + service.authenticateUser(for: .standard, reason: "") { _ in expect(service.isUserAuthenticated(for: .standard)).to(beFalse()) asyncTrigger.trigger() } } it("is true after a successful authentication") { - service.authenticateUser(for: .standard, reason: "") { result in + service.authenticateUser(for: .standard, reason: "") { _ in expect(service.isUserAuthenticated(for: .standard)).to(beTrue()) asyncTrigger.trigger() } } it("becomes false when authentication cache is reset") { - service.authenticateUser(for: .standard, reason: "") { result in + service.authenticateUser(for: .standard, reason: "") { _ in expect(service.isUserAuthenticated(for: .standard)).to(beTrue()) service.resetUserAuthentication(for: .standard) expect(service.isUserAuthenticated(for: .standard)).to(beFalse()) @@ -111,8 +111,8 @@ class CachedAuthenticationServiceProxyTests: QuickSpec { it("resets all state") { let auth = Authentication(id: "another-auth") - service.authenticateUser(for: .standard, reason: "") { result in - service.authenticateUser(for: auth, reason: "") { result in + service.authenticateUser(for: .standard, reason: "") { _ in + service.authenticateUser(for: auth, reason: "") { _ in expect(service.isUserAuthenticated(for: .standard)).to(beTrue()) expect(service.isUserAuthenticated(for: auth)).to(beTrue()) service.resetUserAuthentication() @@ -129,8 +129,8 @@ class CachedAuthenticationServiceProxyTests: QuickSpec { it("resets a single state") { let auth = Authentication(id: "another-auth") - service.authenticateUser(for: .standard, reason: "") { result in - service.authenticateUser(for: auth, reason: "") { result in + service.authenticateUser(for: .standard, reason: "") { _ in + service.authenticateUser(for: auth, reason: "") { _ in expect(service.isUserAuthenticated(for: .standard)).to(beTrue()) expect(service.isUserAuthenticated(for: auth)).to(beTrue()) service.resetUserAuthentication(for: .standard) diff --git a/Tests/SwiftKitTests/Extensions/Url+QueryParametersTests.swift b/Tests/SwiftKitTests/Extensions/Url+QueryParametersTests.swift index c72a5cb..b4ccd90 100644 --- a/Tests/SwiftKitTests/Extensions/Url+QueryParametersTests.swift +++ b/Tests/SwiftKitTests/Extensions/Url+QueryParametersTests.swift @@ -44,7 +44,9 @@ class Url_QueryParametersTests: QuickSpec { } it("handles encoded query parameters") { - let url = URL(string: "http://foo.bar/home?p1=me%20%26%20you&p2=%C3%A5%C3%A4%C3%B6%C3%85%C3%84%C3%96")! + let url = URL(string: """ +http://foo.bar/home?p1=me%20%26%20you&p2=%C3%A5%C3%A4%C3%B6%C3%85%C3%84%C3%96 +""")! let result = url.queryParameters expect(result.count).to(equal(2)) expect(result[0].name).to(equal("p1")) @@ -78,7 +80,9 @@ class Url_QueryParametersTests: QuickSpec { } it("handles encoded query parameters") { - let url = URL(string: "http://foo.bar/home?p1=me%20%26%20you&p2=%C3%A5%C3%A4%C3%B6%C3%85%C3%84%C3%96")! + let url = URL(string: """ +http://foo.bar/home?p1=me%20%26%20you&p2=%C3%A5%C3%A4%C3%B6%C3%85%C3%84%C3%96 +""")! let result = url.queryParametersDictionary expect(result.count).to(equal(2)) expect(result["p1"]).to(equal("me & you")) diff --git a/Tests/SwiftKitTests/XCTestManifests.swift b/Tests/SwiftKitTests/XCTestManifests.swift index c5513ab..8bfcdaf 100644 --- a/Tests/SwiftKitTests/XCTestManifests.swift +++ b/Tests/SwiftKitTests/XCTestManifests.swift @@ -3,7 +3,7 @@ import XCTest #if !canImport(ObjectiveC) public func allTests() -> [XCTestCaseEntry] { return [ - testCase(SwiftKitTests.allTests), + testCase(SwiftKitTests.allTests) ] } #endif