Make code pass lint validation

This commit is contained in:
Daniel Saidi 2020-09-05 11:52:49 +02:00
parent e56f64daa3
commit 1ca3184fd8
11 changed files with 32 additions and 19 deletions

View File

@ -1,5 +1,8 @@
disabled_rules: disabled_rules:
- function_body_length
- identifier_name - identifier_name
- line_length
- todo
- trailing_whitespace - trailing_whitespace
- type_name - type_name
- vertical_whitespace - vertical_whitespace

View File

@ -14,7 +14,7 @@ import Foundation
*/ */
public protocol AuthenticationService: AnyObject { public protocol AuthenticationService: AnyObject {
typealias AuthCompletion = (_ result: AuthResult) -> () typealias AuthCompletion = (_ result: AuthResult) -> Void
typealias AuthError = AuthenticationServiceError typealias AuthError = AuthenticationServiceError
typealias AuthResult = Result<Void, Error> typealias AuthResult = Result<Void, Error>

View File

@ -12,13 +12,19 @@ public class StandardCsvParser: CsvParser {
public init() {} 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 allRows = string.components(separatedBy: .newlines)
let rows = allRows.filter { $0.trimmingCharacters(in: .whitespaces).count > 0 } let rows = allRows.filter { $0.trimmingCharacters(in: .whitespaces).count > 0 }
return rows.map { $0.split(separator: separator).map { String($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) let url = bundle.url(forResource: fileName, withExtension: ext)
guard let fileUrl = url else { throw CsvParserError.noSuchFile(fileName, fileExtension: ext) } guard let fileUrl = url else { throw CsvParserError.noSuchFile(fileName, fileExtension: ext) }
let data = try Data(contentsOf: fileUrl) let data = try Data(contentsOf: fileUrl)

View File

@ -38,4 +38,3 @@ public extension Date {
calendar.dateComponents([.second], from: date, to: self).second ?? 0 calendar.dateComponents([.second], from: date, to: self).second ?? 0
} }
} }

View File

@ -23,7 +23,7 @@ public extension JSONEncoder {
private extension JSONEncoder.DateEncodingStrategy { 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 formatter = DateFormatter.iso8601Milliseconds
let string = formatter.string(from: date) let string = formatter.string(from: date)
var container = encoder.singleValueContainer() var container = encoder.singleValueContainer()

View File

@ -33,7 +33,7 @@ private extension BundleFileFinder {
let files = try fileManager.contentsOfDirectory(atPath: path) let files = try fileManager.contentsOfDirectory(atPath: path)
let array = files as NSArray let array = files as NSArray
let filteredFiles = array.filtered(using: predicate) let filteredFiles = array.filtered(using: predicate)
return filteredFiles as! [String] return filteredFiles as? [String] ?? []
} catch { } catch {
return [String]() return [String]()
} }

View File

@ -17,8 +17,6 @@ import Foundation
but as soon as you call `setLocale` the standard translator but as soon as you call `setLocale` the standard translator
will replaced with a `BundleTranslator`, that will used the will replaced with a `BundleTranslator`, that will used the
bundle of the new locale. bundle of the new locale.
`TODO` Write unit tests with mocked types for this service.
*/ */
open class StandardLocalizationService: LocalizationService { open class StandardLocalizationService: LocalizationService {

View File

@ -103,7 +103,10 @@ private class TestClass: BiometricAuthenticationService, Mockable {
invoke(canAuthenticateUserRef, args: (auth)) 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)) invoke(performAuthenticationRef, args: (auth, reason, completion))
if let error = authError { return completion(.failure(error)) } if let error = authError { return completion(.failure(error)) }
completion(.success(())) completion(.success(()))

View File

@ -84,21 +84,21 @@ class CachedAuthenticationServiceProxyTests: QuickSpec {
it("is false after a failed authentication") { it("is false after a failed authentication") {
mock.authError = TestError.failure mock.authError = TestError.failure
service.authenticateUser(for: .standard, reason: "") { result in service.authenticateUser(for: .standard, reason: "") { _ in
expect(service.isUserAuthenticated(for: .standard)).to(beFalse()) expect(service.isUserAuthenticated(for: .standard)).to(beFalse())
asyncTrigger.trigger() asyncTrigger.trigger()
} }
} }
it("is true after a successful authentication") { 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()) expect(service.isUserAuthenticated(for: .standard)).to(beTrue())
asyncTrigger.trigger() asyncTrigger.trigger()
} }
} }
it("becomes false when authentication cache is reset") { 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()) expect(service.isUserAuthenticated(for: .standard)).to(beTrue())
service.resetUserAuthentication(for: .standard) service.resetUserAuthentication(for: .standard)
expect(service.isUserAuthenticated(for: .standard)).to(beFalse()) expect(service.isUserAuthenticated(for: .standard)).to(beFalse())
@ -111,8 +111,8 @@ class CachedAuthenticationServiceProxyTests: QuickSpec {
it("resets all state") { it("resets all state") {
let auth = Authentication(id: "another-auth") let auth = Authentication(id: "another-auth")
service.authenticateUser(for: .standard, reason: "") { result in service.authenticateUser(for: .standard, reason: "") { _ in
service.authenticateUser(for: auth, reason: "") { result in service.authenticateUser(for: auth, reason: "") { _ in
expect(service.isUserAuthenticated(for: .standard)).to(beTrue()) expect(service.isUserAuthenticated(for: .standard)).to(beTrue())
expect(service.isUserAuthenticated(for: auth)).to(beTrue()) expect(service.isUserAuthenticated(for: auth)).to(beTrue())
service.resetUserAuthentication() service.resetUserAuthentication()
@ -129,8 +129,8 @@ class CachedAuthenticationServiceProxyTests: QuickSpec {
it("resets a single state") { it("resets a single state") {
let auth = Authentication(id: "another-auth") let auth = Authentication(id: "another-auth")
service.authenticateUser(for: .standard, reason: "") { result in service.authenticateUser(for: .standard, reason: "") { _ in
service.authenticateUser(for: auth, reason: "") { result in service.authenticateUser(for: auth, reason: "") { _ in
expect(service.isUserAuthenticated(for: .standard)).to(beTrue()) expect(service.isUserAuthenticated(for: .standard)).to(beTrue())
expect(service.isUserAuthenticated(for: auth)).to(beTrue()) expect(service.isUserAuthenticated(for: auth)).to(beTrue())
service.resetUserAuthentication(for: .standard) service.resetUserAuthentication(for: .standard)

View File

@ -44,7 +44,9 @@ class Url_QueryParametersTests: QuickSpec {
} }
it("handles encoded query parameters") { 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 let result = url.queryParameters
expect(result.count).to(equal(2)) expect(result.count).to(equal(2))
expect(result[0].name).to(equal("p1")) expect(result[0].name).to(equal("p1"))
@ -78,7 +80,9 @@ class Url_QueryParametersTests: QuickSpec {
} }
it("handles encoded query parameters") { 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 let result = url.queryParametersDictionary
expect(result.count).to(equal(2)) expect(result.count).to(equal(2))
expect(result["p1"]).to(equal("me & you")) expect(result["p1"]).to(equal("me & you"))

View File

@ -3,7 +3,7 @@ import XCTest
#if !canImport(ObjectiveC) #if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] { public func allTests() -> [XCTestCaseEntry] {
return [ return [
testCase(SwiftKitTests.allTests), testCase(SwiftKitTests.allTests)
] ]
} }
#endif #endif