Skip to content

Commit

Permalink
Fixed SwiftLint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Sep 12, 2024
1 parent 80a1670 commit ae1876e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving
let httpResponse = response as? HTTPURLResponse
switch httpResponse?.statusCode {
case 200:
let body = String(decoding: data, as: UTF8.self)
guard let body = String(data: data, encoding: .utf8) else {
throw CryptomatorHubAuthenticatorError.unexpectedResponse
}
return .success(encryptedVaultKey: body, header: httpResponse?.allHeaderFields ?? [:])
case 402:
return .licenseExceeded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public enum CloudProviderType: Codable, Equatable, Hashable {
extension CloudProviderType: DatabaseValueConvertible {
public var databaseValue: DatabaseValue {
let jsonEncoder = JSONEncoder()
guard let data = try? jsonEncoder.encode(self) else {
guard let data = try? jsonEncoder.encode(self), let string = String(data: data, encoding: .utf8) else {
return .null
}
let string = String(decoding: data, as: UTF8.self)
return string.databaseValue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public protocol VaultPasswordManager {
}

public enum VaultPasswordManagerError: Error {
case encodingError
case passwordNotFound
}

Expand Down Expand Up @@ -53,7 +54,9 @@ public class VaultPasswordKeychainManager: VaultPasswordManager {
guard let data = CryptomatorUserPresenceKeychain.vaultPassword.getAsData(vaultUID, context: context) else {
throw VaultPasswordManagerError.passwordNotFound
}
let password = String(decoding: data, as: UTF8.self)
guard let password = String(data: data, encoding: .utf8) else {
throw VaultPasswordManagerError.encodingError
}
return password
}
}
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/FileProviderEnumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {

var pageToken: String?
if page != NSFileProviderPage.initialPageSortedByDate as NSFileProviderPage, page != NSFileProviderPage.initialPageSortedByName as NSFileProviderPage {
pageToken = String(decoding: page.rawValue, as: UTF8.self)
pageToken = String(data: page.rawValue, encoding: .utf8)
}
DDLogDebug("enumerateItems called for identifier: \(enumeratedItemIdentifier) - initialPage \(pageToken == nil)")
adapterProvider.unlockMonitor.execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FileProviderAdapterImportDocumentTests: FileProviderAdapterTestCase {

// Check that file was copied to the url provided by the localURLProvider
XCTAssert(FileManager.default.fileExists(atPath: expectedFileURL.path))
let contentOfCopiedFile = try String(decoding: Data(contentsOf: expectedFileURL), as: UTF8.self)
let contentOfCopiedFile = try String(data: Data(contentsOf: expectedFileURL), encoding: .utf8)
XCTAssertEqual(fileContent, contentOfCopiedFile)
// Check that the original file was not altered
XCTAssert(FileManager.default.contentsEqual(atPath: fileURL.path, andPath: expectedFileURL.path))
Expand Down Expand Up @@ -101,7 +101,7 @@ class FileProviderAdapterImportDocumentTests: FileProviderAdapterTestCase {

// Check that existing file at the url provided by the localURLProvider was not overwritten
XCTAssert(FileManager.default.fileExists(atPath: expectedFileURL.path))
let contentOfCopiedFile = try String(decoding: Data(contentsOf: expectedFileURL), as: UTF8.self)
let contentOfCopiedFile = try String(data: Data(contentsOf: expectedFileURL), encoding: .utf8)
XCTAssertEqual(existingFileContent, contentOfCopiedFile)

XCTAssertEqual(1, metadataManagerMock.removedMetadataID.count)
Expand Down Expand Up @@ -140,7 +140,7 @@ class FileProviderAdapterImportDocumentTests: FileProviderAdapterTestCase {
XCTAssert(FileManager.default.fileExists(atPath: self.expectedFileURL.path))
let contentOfCopiedFile: String?
do {
contentOfCopiedFile = try String(decoding: Data(contentsOf: self.expectedFileURL), as: UTF8.self)
contentOfCopiedFile = try String(data: Data(contentsOf: self.expectedFileURL), encoding: .utf8)
} catch {
XCTFail("Content of copied file failed with error: \(error)")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,9 @@ class ItemEnumerationTaskTests: CloudTaskExecutorTestCase {
XCTAssertEqual(2, fileProviderItemList.items.count)
// Check that a next page exists
XCTAssertNotNil(fileProviderItemList.nextPageToken)
guard let tokenData = fileProviderItemList.nextPageToken else {
guard let tokenData = fileProviderItemList.nextPageToken, let nextPageToken = String(data: tokenData.rawValue, encoding: .utf8) else {
throw NSError(domain: "ItemEnumerationTaskExecutorTestError", code: -100, userInfo: ["localizedDescription": "No page token"])
}
let nextPageToken = String(decoding: tokenData.rawValue, as: UTF8.self)
// Check that the (possible) old items have been marked as maybe outdated
XCTAssert(self.metadataManagerMock.cachedMetadata[2]?.isMaybeOutdated ?? false)
XCTAssert(self.metadataManagerMock.cachedMetadata[3]?.isMaybeOutdated ?? false)
Expand Down

0 comments on commit ae1876e

Please sign in to comment.