From 7b0b823bc8aa81a9b7523d987c3ebfc5c928ef4e Mon Sep 17 00:00:00 2001 From: Jason R Tibbetts Date: Sat, 11 Jan 2020 00:34:10 -0500 Subject: [PATCH] #45: Fixed things that SwiftLint complained about. --- Source/Collection/CollectionCustomField.swift | 12 ++-- Source/Collection/CollectionFolder.swift | 8 +-- Source/Collection/CollectionFolderItem.swift | 2 +- Source/Collection/CollectionItemInfo.swift | 4 +- Source/Collection/CollectionRelease.swift | 2 +- Source/Collection/CollectionValue.swift | 4 +- Source/Database/ArtistSummary.swift | 4 +- Source/Database/Community.swift | 2 +- Source/Database/Image.swift | 2 +- Source/Database/MasterRelease.swift | 4 ++ Source/Database/MasterReleaseVersion.swift | 10 ++- Source/Database/ReleaseRating.swift | 2 +- Source/Database/ReleaseSummary.swift | 14 ++-- Source/Database/SearchResults.swift | 10 ++- Source/Database/Track.swift | 2 +- Source/Discogs.swift | 30 ++++---- Source/DiscogsClient.swift | 68 +++++++++++-------- Source/HasArtistSummaries.swift | 8 +-- Source/Mock Implementation/MockDiscogs.swift | 44 ++++++------ Source/Pagination.swift | 2 +- Source/User Identity/UserProfile.swift | 4 +- SwiftDiscogsApp/AppDelegate.swift | 27 +++++--- .../Artist/DiscogsArtistModel.swift | 6 +- SwiftDiscogsApp/DiscogsDisplay.swift | 2 +- .../MPMediaCollectionBrowser.swift | 7 +- .../MPMediaCollectionImporter.swift | 2 +- .../MediaLibrary/MediaLibrary.swift | 2 +- .../Player/MediaSourcesDisplay.swift | 5 +- .../Release/MasterReleaseViewController.swift | 8 +-- SwiftDiscogsApp/Release/ReleaseModel.swift | 3 +- .../Search/DiscogsSearchResultsModel.swift | 8 +-- .../Search/DiscogsSearchViewController.swift | 2 +- SwiftDiscogsApp/SectionedModel.swift | 15 ++-- SwiftDiscogsApp/Song/Song.swift | 2 +- .../Discogs/DiscogsCollectionImporter.swift | 16 +++-- .../Discogs/DiscogsService.swift | 6 +- .../Discogs/DiscogsSignInViewController.swift | 6 +- .../ThirdPartyService.swift | 5 +- .../ThirdPartyServicesViewController.swift | 2 +- .../Player/PlayerViewTests.swift | 7 +- .../SectionedModelTests.swift | 10 +-- .../SwiftDiscogsAppUITests.swift | 30 ++++---- Tests/ClientTestBase.swift | 2 +- .../CollectionCustomFieldsTests.swift | 12 ++-- .../CollectionFolderItemsTests.swift | 9 ++- .../Collection/CollectionItemInfoTests.swift | 7 +- Tests/Collection/CollectionValueTests.swift | 10 +-- Tests/Database/ArtistTests.swift | 10 +-- Tests/Database/LabelReleasesTests.swift | 11 ++- Tests/Database/LabelTests.swift | 8 +-- Tests/Database/MasterReleaseTests.swift | 8 +-- Tests/Database/ReleaseSummaryTests.swift | 6 +- Tests/Database/ReleaseTests.swift | 9 ++- Tests/DiscogsClientTests.swift | 46 +++++++------ Tests/DiscogsTestBase.swift | 2 +- Tests/JSONTestBase.swift | 1 - Tests/User Identity/UserIdentityTests.swift | 8 +-- Tests/User Identity/UserProfileTests.swift | 6 +- 58 files changed, 300 insertions(+), 264 deletions(-) diff --git a/Source/Collection/CollectionCustomField.swift b/Source/Collection/CollectionCustomField.swift index 78d1690..10744b0 100644 --- a/Source/Collection/CollectionCustomField.swift +++ b/Source/Collection/CollectionCustomField.swift @@ -4,28 +4,28 @@ import Foundation /// A user-defined column in the collection database. public struct CollectionCustomField: Codable { - + /// Determines what type of editing/display component to use when /// entering data on Discogs.com. public enum FieldType: String { case dropdown case textarea } - + /// The field's unique ID within the set of fields. public var id: Int /// If this is a text-area field, this is the number of lines that /// should be displayed. public var lines: Int? - + /// The name of the field. public var name: String - + /// For dropdown fields, these are the option strings to display. They /// will appear in the order they're specified. public var options: [String]? - + /// The index of this field among all fields. public var position: Int @@ -41,7 +41,7 @@ public struct CollectionCustomField: Codable { /// A collection of the custom fields that a user has defined. public struct CollectionCustomFields: Codable { - + /// The custom fields that the user has defined, if any. public var fields: [CollectionCustomField]? diff --git a/Source/Collection/CollectionFolder.swift b/Source/Collection/CollectionFolder.swift index eb2dfcf..ad5f271 100644 --- a/Source/Collection/CollectionFolder.swift +++ b/Source/Collection/CollectionFolder.swift @@ -4,17 +4,17 @@ import Foundation /// A JSON element that contains the folders array. public struct CollectionFolders: Codable { - + public var folders: [CollectionFolder] - + } /// Information about a folder in a user's collection. public struct CollectionFolder: Codable, Unique { - + public var id: Int public var count: Int public var name: String public var resourceUrl: String - + } diff --git a/Source/Collection/CollectionFolderItem.swift b/Source/Collection/CollectionFolderItem.swift index 59dae28..fa8e19a 100644 --- a/Source/Collection/CollectionFolderItem.swift +++ b/Source/Collection/CollectionFolderItem.swift @@ -10,7 +10,7 @@ public struct CollectionFolderItems: Codable, Pageable { } public struct CollectionFolderItem: Codable { - + public var folderId: Int public var id: Int public var basicInformation: Info? diff --git a/Source/Collection/CollectionItemInfo.swift b/Source/Collection/CollectionItemInfo.swift index 7ec4c59..9535d03 100644 --- a/Source/Collection/CollectionItemInfo.swift +++ b/Source/Collection/CollectionItemInfo.swift @@ -3,8 +3,8 @@ import Foundation public struct CollectionItemInfo: Codable { - + public var instanceId: Int public var resourceUrl: String - + } diff --git a/Source/Collection/CollectionRelease.swift b/Source/Collection/CollectionRelease.swift index b6d0cf7..c5ea295 100644 --- a/Source/Collection/CollectionRelease.swift +++ b/Source/Collection/CollectionRelease.swift @@ -3,7 +3,7 @@ import Foundation public struct CollectionRelease: Codable { - + public var basicInformation: [Information]? public var folderId: Int public var id: Int diff --git a/Source/Collection/CollectionValue.swift b/Source/Collection/CollectionValue.swift index 1524d84..315b372 100644 --- a/Source/Collection/CollectionValue.swift +++ b/Source/Collection/CollectionValue.swift @@ -3,9 +3,9 @@ import Foundation public struct CollectionValue: Codable { - + public var maximum: String public var median: String public var minimum: String - + } diff --git a/Source/Database/ArtistSummary.swift b/Source/Database/ArtistSummary.swift index 68415c0..d794aea 100644 --- a/Source/Database/ArtistSummary.swift +++ b/Source/Database/ArtistSummary.swift @@ -3,7 +3,7 @@ import Foundation public struct ArtistSummary: Codable, Unique { - + public var artistNameVariation: String? public var id: Int public var join: String? @@ -21,5 +21,5 @@ public struct ArtistSummary: Codable, Unique { case role case tracks } - + } diff --git a/Source/Database/Community.swift b/Source/Database/Community.swift index 9b6d8d5..6f035c6 100644 --- a/Source/Database/Community.swift +++ b/Source/Database/Community.swift @@ -3,7 +3,7 @@ import Foundation public struct Community: Codable { - + public var have: Int public var want: Int diff --git a/Source/Database/Image.swift b/Source/Database/Image.swift index c13c19e..b79b39d 100644 --- a/Source/Database/Image.swift +++ b/Source/Database/Image.swift @@ -10,5 +10,5 @@ public struct Image: Codable { public var uri: String public var uri150: String public var width: Int - + } diff --git a/Source/Database/MasterRelease.swift b/Source/Database/MasterRelease.swift index d7bec33..6691a01 100644 --- a/Source/Database/MasterRelease.swift +++ b/Source/Database/MasterRelease.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct MasterRelease: Codable, Unique { public var artists: [ArtistSummary] @@ -43,3 +45,5 @@ public struct MasterRelease: Codable, Unique { } } + +// swiftlint:enable identifier_name diff --git a/Source/Database/MasterReleaseVersion.swift b/Source/Database/MasterReleaseVersion.swift index df34444..4093443 100644 --- a/Source/Database/MasterReleaseVersion.swift +++ b/Source/Database/MasterReleaseVersion.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct MasterReleaseVersion: Codable, Unique { public var catalogNumber: String? @@ -27,7 +29,7 @@ public struct MasterReleaseVersion: Codable, Unique { return nil } } - + public var majorFormat: String? { return majorFormats?.first } @@ -49,8 +51,10 @@ public struct MasterReleaseVersion: Codable, Unique { } public struct MasterReleaseVersions: Codable, Pageable { - + public var pagination: Pagination? public var versions: [MasterReleaseVersion] - + } + +// swiftlint:enable identifier_name diff --git a/Source/Database/ReleaseRating.swift b/Source/Database/ReleaseRating.swift index b1019a5..881ad26 100644 --- a/Source/Database/ReleaseRating.swift +++ b/Source/Database/ReleaseRating.swift @@ -3,7 +3,7 @@ import Foundation public struct ReleaseRating: Codable { - + public var average: Float public var count: Int diff --git a/Source/Database/ReleaseSummary.swift b/Source/Database/ReleaseSummary.swift index d268e36..1bf6820 100644 --- a/Source/Database/ReleaseSummary.swift +++ b/Source/Database/ReleaseSummary.swift @@ -3,7 +3,7 @@ import Foundation public struct ReleaseSummary: Codable, Unique { - + public var artist: String public var catno: String? public var catalogNumber: String? { return catno } @@ -18,20 +18,20 @@ public struct ReleaseSummary: Codable, Unique { public var title: String public var type: String? public var year: Int? - + public var formats: [String]? { return format?.components(separatedBy: ",").map { (substringChars) -> String in let substring = String(substringChars) - + return substring.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - } + } } - + } public struct ReleaseSummaries: Codable, Pageable { - + public var pagination: Pagination? public var releases: [ReleaseSummary]? - + } diff --git a/Source/Database/SearchResults.swift b/Source/Database/SearchResults.swift index a0f69cf..7572e5e 100644 --- a/Source/Database/SearchResults.swift +++ b/Source/Database/SearchResults.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct SearchResult: Codable, Unique { public var catalogNumber: String? @@ -35,11 +37,13 @@ public struct SearchResult: Codable, Unique { case uri case year } - + } public struct SearchResults: Codable { - + public var results: [SearchResult]? - + } + +// swiftlint:enable identifier_name diff --git a/Source/Database/Track.swift b/Source/Database/Track.swift index 8bac5a7..df6bddd 100644 --- a/Source/Database/Track.swift +++ b/Source/Database/Track.swift @@ -3,7 +3,7 @@ import Foundation public struct Track: Codable { - + public var duration: String public var position: String public var type: String diff --git a/Source/Discogs.swift b/Source/Discogs.swift index f403944..ecba6db 100644 --- a/Source/Discogs.swift +++ b/Source/Discogs.swift @@ -6,21 +6,21 @@ import PromiseKit /// Error types for problems retrieving data from Discogs. public enum DiscogsError: Error { - + /// Thrown when no artist was found when searching by its ID. case artistNotFoundById(Int) - + case discogsResponse(ErrorResponse) - + case labelNotFoundById(Int) - + /// Thrown when no artist was found when searching by its name. case masterReleaseNotFoundById(Int) case releaseNotFoundById(Int) case unauthenticatedUser case unknownUser(username: String) case unknown(Error?) - + } /// Implemented by clients of a Discogs API server. @@ -29,18 +29,18 @@ public protocol Discogs { // MARK: - User Identify var isSignedIn: Bool { get } - + func authorize(presentingViewController: UIViewController, callbackUrlString: String) -> Promise func signOut() - + func userIdentity() -> Promise func userProfile(userName: String) -> Promise // MARK: - Database - + /// Look up the artist with the specified ID and invoke the completion on /// it. /// @@ -55,28 +55,28 @@ public protocol Discogs { /// - parameter completion: The completion block that will be applied to /// all of the artist's releases, or to the error, if one was thrown. func releases(forArtist artistId: Int) -> Promise - + /// Look up the record label by its ID. /// /// - parameter identifier: The label's unique ID. /// - parameter completion: The completion block that will be applied to /// the label, or to the error, if one was thrown. func label(identifier: Int) -> Promise - + /// Look up the record label's releases by the label's name. /// /// - parameter labelId: The label's unique ID. /// - parameter completion: The completion block that will be applied to /// all of the label's releases, or to the error, if one was thrown. func releases(forLabel labelId: Int) -> Promise - + /// Process a master release with a specified ID. /// /// - parameter identifier: The unique ID of the master release. /// - parameter completion: The completion block that will be applied to /// the master release, or to the error, if one was thrown. func masterRelease(identifier: Int) -> Promise - + /// Process all of the release versions that belong to a master release. /// /// - parameter identifier: The unique ID of the master release. @@ -84,16 +84,16 @@ public protocol Discogs { func releasesForMasterRelease(_ identifier: Int, pageNumber: Int, resultsPerPage: Int) -> Promise - + /// Process a release with a specified ID. /// /// - parameter identifier: The unique ID of the release. /// - parameter completion: The completion block that will be applied to /// the release, or to the error, if one was thrown. func release(identifier: Int) -> Promise - + // MARK: - Collections - + func customCollectionFields(forUserName: String) -> Promise func collectionValue(forUserName: String) -> Promise func collectionFolders(forUserName: String) -> Promise diff --git a/Source/DiscogsClient.swift b/Source/DiscogsClient.swift index 615954c..6120330 100644 --- a/Source/DiscogsClient.swift +++ b/Source/DiscogsClient.swift @@ -12,11 +12,11 @@ open class DiscogsClient: OAuth1JSONClient, Discogs { public private(set) var userAgent: String // MARK: - Private properties - + private var headers: OAuthSwift.Headers = [:] // MARK: - Initializers - + /// Initialize the Discogs client. This doesn't make any calls to the /// Discogs API; that happens in `authorize()`. public init(consumerKey: String, @@ -25,7 +25,7 @@ open class DiscogsClient: OAuth1JSONClient, Discogs { self.userAgent = userAgent let jsonDecoder = JSONDecoder() jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase - + super.init(consumerKey: consumerKey, consumerSecret: consumerSecret, requestTokenUrl: "https://api.discogs.com/oauth/request_token", @@ -42,13 +42,16 @@ open class DiscogsClient: OAuth1JSONClient, Discogs { callbackUrlString: String) -> Promise { let promise: Promise = super.authorize(presentingViewController: presentingViewController, callbackUrlString: callbackUrlString) - + return promise } // MARK: - JSONClient - open override func get(path: String, headers: JSONClient.Headers = Headers(), parameters: JSONClient.Parameters = Parameters()) -> Promise where T : Decodable, T : Encodable { + open override func get(path: String, + headers: JSONClient.Headers = Headers(), + parameters: JSONClient.Parameters = Parameters()) + -> Promise where T: Decodable, T: Encodable { print("GET for \(path); headers: \(headers); params: \(parameters)") debugPrint(path, headers, parameters) return super.get(path: path, headers: headers, parameters: parameters) @@ -56,48 +59,51 @@ open class DiscogsClient: OAuth1JSONClient, Discogs { // MARK: - AuthorizedJSONClient - open override func authorizedGet(path: String, headers: AuthorizedJSONClient.Headers = Headers(), parameters: AuthorizedJSONClient.Parameters = Parameters()) -> Promise where T : Decodable, T : Encodable { + open override func authorizedGet(path: String, + headers: AuthorizedJSONClient.Headers = Headers(), + parameters: AuthorizedJSONClient.Parameters = Parameters()) + -> Promise where T: Decodable, T: Encodable { print("Authorized GET for \(path); headers: \(headers); params: \(parameters)") debugPrint(path, headers, parameters) return super.authorizedGet(path: path, headers: headers, parameters: parameters) } // MARK: - Authorization & User Identity - + public func userIdentity() -> Promise { return authorizedGet(path: "/oauth/identity", headers: headers) } - + public func userProfile(userName: String) -> Promise { return authorizedGet(path: "/users/\(userName)", headers: headers) } - + // MARK: - Database - + public func artist(identifier: Int) -> Promise { return get(path: "/artists/\(identifier)", headers: headers) } - + public func label(identifier: Int) -> Promise { return get(path: "/labels/\(identifier)", headers: headers) } - + public func masterRelease(identifier: Int) -> Promise { return get(path: "/masters/\(identifier)", headers: headers) } - + public func release(identifier: Int) -> Promise { return get(path: "/releases/\(identifier)", headers: headers) } - + public func releases(forArtist artistId: Int) -> Promise { return get(path: "/artists/\(artistId)/releases", headers: headers) } - + public func releases(forLabel labelId: Int) -> Promise { return get(path: "/labels/\(labelId)/releases", headers: headers) } - + public func releasesForMasterRelease(_ identifier: Int, pageNumber: Int = 1, resultsPerPage: Int = 50) -> Promise { @@ -106,34 +112,34 @@ open class DiscogsClient: OAuth1JSONClient, Discogs { headers: headers, parameters: ["per_page": "\(resultsPerPage)", "page": "\(pageNumber)"]) } - + // MARK: - Collections - + public func customCollectionFields(forUserName userName: String) -> Promise { return authorizedGet(path: "/users/\(userName)/collection/fields", headers: headers) } - + public func collectionValue(forUserName userName: String) -> Promise { return authorizedGet(path: "/users/\(userName)/collection/value", headers: headers) } - + public func collectionFolders(forUserName userName: String) -> Promise { return authorizedGet(path: "/users/\(userName)/collection/folders", headers: headers) } - + public func collectionFolderInfo(forFolderID folderID: Int, userName: String) -> Promise { return authorizedGet(path: "/users/\(userName)/collection/folders/\(folderID)", headers: headers) } - + public func createFolder(named folderName: String, forUserName userName: String) -> Promise { return authorizedPost(path: "/users/\(userName)/collection/folders/\(folderName)", headers: headers) } - + public func edit(_ folder: CollectionFolder, forUserName userName: String) -> Promise { - return Promise { (seal) in + return Promise { _ in } } @@ -145,20 +151,22 @@ open class DiscogsClient: OAuth1JSONClient, Discogs { headers: headers, parameters: ["per_page": "\(resultsPerPage)", "page": "\(pageNumber)"]) } - + public func addItem(_ itemID: Int, toFolderID folderID: Int, userName: String) -> Promise { - return authorizedPost(path: "/users/\(userName)/collection/folders/\(folderID)/releases/{itemId}", headers: headers) + return authorizedPost( + path: "/users/\(userName)/collection/folders/\(folderID)/releases/{itemId}", + headers: headers) } - + // MARK: - Search - + public func search(for queryString: String, type: String) -> Promise { let params = ["q": queryString] - + return authorizedGet(path: "/database/search", headers: headers, parameters: params) } - + } diff --git a/Source/HasArtistSummaries.swift b/Source/HasArtistSummaries.swift index eae4f53..737352f 100644 --- a/Source/HasArtistSummaries.swift +++ b/Source/HasArtistSummaries.swift @@ -3,13 +3,13 @@ import Foundation public protocol HasArtistSummaries { - + var artists: [ArtistSummary]? { get set } - + } extension HasArtistSummaries { - + public var artistString: String { if let artists = artists { return artists.map { $0.name }.joined(separator: L10n.separator) @@ -17,5 +17,5 @@ extension HasArtistSummaries { return L10n.unknownArtist } } - + } diff --git a/Source/Mock Implementation/MockDiscogs.swift b/Source/Mock Implementation/MockDiscogs.swift index 5631ab2..b413eda 100644 --- a/Source/Mock Implementation/MockDiscogs.swift +++ b/Source/Mock Implementation/MockDiscogs.swift @@ -8,7 +8,7 @@ import UIKit /// A `Discogs` implementation that generates canned values from the sample /// JSON code documented at api.discogs.com. public class MockDiscogs: MockClient, Discogs { - + public init(errorMode: Bool = false) { let bundle = Bundle(for: MockDiscogs.self) let jsonDecoder = JSONDecoder() @@ -40,7 +40,7 @@ public class MockDiscogs: MockClient, Discogs { public func signOut() { // There's nothing to do. } - + public func userIdentity() -> Promise { return apply(toJsonObjectIn: "get-user-identity-200", error: DiscogsError.unauthenticatedUser) @@ -50,81 +50,81 @@ public class MockDiscogs: MockClient, Discogs { return apply(toJsonObjectIn: "get-user-profile-200", error: DiscogsError.unauthenticatedUser) } - + // MARK: - Database - + public func artist(identifier: Int) -> Promise { return apply(toJsonObjectIn: "get-artist-200", error: DiscogsError.artistNotFoundById(identifier)) } - + public func releases(forArtist artistId: Int) -> Promise { return apply(toJsonObjectIn: "get-release-summaries-200", error: DiscogsError.artistNotFoundById(artistId)) } - + public func label(identifier: Int) -> Promise { return apply(toJsonObjectIn: "get-label-200", error: DiscogsError.labelNotFoundById(identifier)) } - + public func releases(forLabel labelId: Int) -> Promise { return apply(toJsonObjectIn: "get-label-releases-200", error: DiscogsError.labelNotFoundById(labelId)) } - + public func masterRelease(identifier: Int) -> Promise { return apply(toJsonObjectIn: "get-master-200", error: DiscogsError.masterReleaseNotFoundById(identifier)) } - + public func releasesForMasterRelease(_ identifier: Int, pageNumber: Int = 0, resultsPerPage: Int = 50) -> Promise { return apply(toJsonObjectIn: "get-master-release-versions-200", error: DiscogsError.masterReleaseNotFoundById(identifier)) } - + public func release(identifier: Int) -> Promise { return apply(toJsonObjectIn: "get-release-200", error: DiscogsError.masterReleaseNotFoundById(identifier)) } - + // MARK: - Collections - + public func customCollectionFields(forUserName userName: String) -> Promise { return apply(toJsonObjectIn: "get-custom-fields-200", error: DiscogsError.unknownUser(username: userName)) } - + public func collectionValue(forUserName userName: String) -> Promise { return apply(toJsonObjectIn: "get-collection-value-200", error: DiscogsError.unknownUser(username: userName)) } - + public func collectionFolders(forUserName userName: String) -> Promise { return apply(toJsonObjectIn: "get-folders-200", error: DiscogsError.unknownUser(username: userName)) } - + public func collectionFolderInfo(forFolderID folderID: Int, userName: String) -> Promise { return apply(toJsonObjectIn: "get-folder-metadata-200", error: DiscogsError.unknownUser(username: userName)) } - + public func createFolder(named folderName: String, forUserName userName: String) -> Promise { return apply(toJsonObjectIn: "post-create-folder-201", error: DiscogsError.unknownUser(username: userName)) } - + public func edit(_ folder: CollectionFolder, forUserName userName: String) -> Promise { return apply(toJsonObjectIn: "post-edit-folder-metadata-200", error: DiscogsError.unknownUser(username: userName)) } - + public func collectionItems(inFolderID folderID: Int, userName: String, pageNumber: Int = 1, @@ -132,19 +132,19 @@ public class MockDiscogs: MockClient, Discogs { return apply(toJsonObjectIn: "get-items-in-folder-200", error: DiscogsError.unknownUser(username: userName)) } - + public func addItem(_ itemID: Int, toFolderID folderID: Int, userName: String) -> Promise { return apply(toJsonObjectIn: "add-item-to-collection-folder-200", error: DiscogsError.unknownUser(username: userName)) } - + // MARK: - Search - + public func search(for queryString: String, type: String = "title") -> Promise { return apply(toJsonObjectIn: "search-200", error: DiscogsError.unknown(nil)) } - + } diff --git a/Source/Pagination.swift b/Source/Pagination.swift index b407b6d..8ca1664 100644 --- a/Source/Pagination.swift +++ b/Source/Pagination.swift @@ -14,6 +14,6 @@ public struct Pagination: Codable { public var pages: Int public var items: Int public var perPage: Int - public var urls: [String : URL] + public var urls: [String: URL] } diff --git a/Source/User Identity/UserProfile.swift b/Source/User Identity/UserProfile.swift index 7827eac..a158414 100644 --- a/Source/User Identity/UserProfile.swift +++ b/Source/User Identity/UserProfile.swift @@ -3,7 +3,7 @@ import Foundation public struct UserProfile: Codable { - + public var avatarUrl: String public var bannerUrl: String public var buyerNumRatings: Int @@ -35,5 +35,5 @@ public struct UserProfile: Codable { public var uri: String public var username: String public var wantlistUrl: URL - + } diff --git a/SwiftDiscogsApp/AppDelegate.swift b/SwiftDiscogsApp/AppDelegate.swift index c871058..744ab53 100644 --- a/SwiftDiscogsApp/AppDelegate.swift +++ b/SwiftDiscogsApp/AppDelegate.swift @@ -55,18 +55,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let discogsBundle = Bundle(for: type(of: self)) let model = NSManagedObjectModel.mergedModel(from: [medi8Bundle, discogsBundle])! let container = NSPersistentContainer(name: "Medi8", managedObjectModel: model) - container.loadPersistentStores(completionHandler: { (storeDescription, error) in + container.loadPersistentStores(completionHandler: { (_, error) in if let error = error as NSError? { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + // Replace this implementation with code to handle the error + // appropriately. + // fatalError() causes the application to generate a crash log + // and terminate. You should not use this function in a + // shipping application, although it may be useful during + // development. /* Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. + * The parent directory does not exist, cannot be created, or + * disallows writing. + * The persistent store is not accessible, due to permissions + * or data protection when the device is locked. * The device is out of space. * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. + * Check the error message to determine what the actual problem + * was. */ fatalError("Unresolved error \(error), \(error.userInfo)") } @@ -81,8 +88,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { do { try context.save() } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + // Replace this implementation with code to handle the error + // appropriately. + // fatalError() causes the application to generate a crash log + // and terminate. You should not use this function in a + // shipping application, although it may be useful during + // development. let nserror = error as NSError fatalError("Unresolved error \(nserror), \(nserror.userInfo)") } diff --git a/SwiftDiscogsApp/Artist/DiscogsArtistModel.swift b/SwiftDiscogsApp/Artist/DiscogsArtistModel.swift index c795746..3f7883c 100644 --- a/SwiftDiscogsApp/Artist/DiscogsArtistModel.swift +++ b/SwiftDiscogsApp/Artist/DiscogsArtistModel.swift @@ -33,7 +33,7 @@ open class DiscogsArtistModel: SectionedModel { } } - + // MARK: Private Properties private var bioSection = BioSection(cellID: "artistBioCell") @@ -99,8 +99,8 @@ open class DiscogsArtistModel: SectionedModel { let releaseSummary = releases?[releaseIndex] if let cell = cell as? DiscogsArtistReleaseTableCell { - if let summaryTitle = releaseSummary?.title.lowercased(), - let albums = mediaCollections?.filter({ $0.representativeItem?.title?.lowercased() == summaryTitle }), + if let title = releaseSummary?.title.lowercased(), + let albums = mediaCollections?.filter({ $0.representativeItem?.title?.lowercased() == title }), albums.count > 0 { cell.inLibrary = true } diff --git a/SwiftDiscogsApp/DiscogsDisplay.swift b/SwiftDiscogsApp/DiscogsDisplay.swift index e4e583d..15255d8 100644 --- a/SwiftDiscogsApp/DiscogsDisplay.swift +++ b/SwiftDiscogsApp/DiscogsDisplay.swift @@ -22,7 +22,7 @@ open class DiscogsDisplay: CollectionAndTableDisplay { /// Shut down, turn off, and/or remove any UI components that need explicit /// removal. func tearDown() { - + } } diff --git a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift index d62ef51..8582991 100644 --- a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift +++ b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift @@ -42,13 +42,13 @@ public extension MPMediaCollectionBrowser { if let collections = query.collections { let totalCount = collections.count - collections.enumerated().forEach({ (__val:(Int, MPMediaItemCollection)) in let (index,collection) = __val; + collections.enumerated().forEach({ (_val:(Int, MPMediaItemCollection)) in let (index, collection) = __val; do { inspect(collection, at: index) browserDelegate?.willInspect(mediaCollection: collection, at: index, outOf: totalCount) let totalItemCount = collection.items.count - collection.items.enumerated().forEach({ (__val:(Int, MPMediaItem)) in let (index,item) = __val; + collection.items.enumerated().forEach({ (_val:(Int, MPMediaItem)) in let (index, item) = __val; browserDelegate?.willInspect(mediaItem: item, at: index, outOf: totalItemCount) inspect(item, at: index) }) @@ -89,8 +89,7 @@ open class MPMediaCollectionBrowserDelegate: MediaImporter.Delegate { open func willInspect(mediaItem: MPMediaItem, at index: Int, outOf total: Int) { - + } } - diff --git a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift index 99f0f5c..52ae7c5 100644 --- a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift +++ b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift @@ -67,5 +67,5 @@ public class MPMediaItemCollectionImporter: MediaImporter, MPMediaCollectionBrow print("Error: \(error)") } } - + } diff --git a/SwiftDiscogsApp/MediaLibrary/MediaLibrary.swift b/SwiftDiscogsApp/MediaLibrary/MediaLibrary.swift index 366e1fb..53200f2 100644 --- a/SwiftDiscogsApp/MediaLibrary/MediaLibrary.swift +++ b/SwiftDiscogsApp/MediaLibrary/MediaLibrary.swift @@ -7,7 +7,7 @@ import MediaPlayer public protocol MediaLibrary { func albums(byArtistNamed: String?) -> [MPMediaItemCollection]? - + /// Get all on-device media items by artists whose names contain the /// specified string. /// diff --git a/SwiftDiscogsApp/Player/MediaSourcesDisplay.swift b/SwiftDiscogsApp/Player/MediaSourcesDisplay.swift index 49e8c67..5fb51a6 100644 --- a/SwiftDiscogsApp/Player/MediaSourcesDisplay.swift +++ b/SwiftDiscogsApp/Player/MediaSourcesDisplay.swift @@ -47,7 +47,7 @@ public class MediaSourceView: UIView { @IBOutlet public weak var nameLabel: UILabel? @IBOutlet public weak var signedInAsLabel: UILabel? - + @IBOutlet public weak var signInButton: UIButton? @IBOutlet public weak var signOutButton: UIButton? @@ -55,6 +55,5 @@ public class MediaSourceView: UIView { @IBOutlet public weak var signOutStack: UIStackView? @IBOutlet public weak var spinner: UIActivityIndicatorView? - -} +} diff --git a/SwiftDiscogsApp/Release/MasterReleaseViewController.swift b/SwiftDiscogsApp/Release/MasterReleaseViewController.swift index 32bd59e..f36a444 100644 --- a/SwiftDiscogsApp/Release/MasterReleaseViewController.swift +++ b/SwiftDiscogsApp/Release/MasterReleaseViewController.swift @@ -79,14 +79,14 @@ public class MasterReleaseViewController: BaseReleaseViewController { // MARK: - Private Properties private let versionsSection = Section(cellID: "versionCell", headerText: L10n.versions) - + // MARK: - Initialization - + public override init() { super.init() sections = [tracklistSection, versionsSection] } - + // MARK: - UITableViewDataSource open override func tableView(_ tableView: UITableView, @@ -119,5 +119,5 @@ public class MasterReleaseViewController: BaseReleaseViewController { } } - + } diff --git a/SwiftDiscogsApp/Release/ReleaseModel.swift b/SwiftDiscogsApp/Release/ReleaseModel.swift index 7dada74..4b416fb 100644 --- a/SwiftDiscogsApp/Release/ReleaseModel.swift +++ b/SwiftDiscogsApp/Release/ReleaseModel.swift @@ -11,7 +11,7 @@ public class ReleaseModel: SectionedModel { tracks = masterRelease?.tracklist } } - + public var tracks: [Track]? public let tracklistSection = Section(cellID: "trackCell", headerText: L10n.tracklist) @@ -45,4 +45,3 @@ public class ReleaseModel: SectionedModel { } } } - diff --git a/SwiftDiscogsApp/Search/DiscogsSearchResultsModel.swift b/SwiftDiscogsApp/Search/DiscogsSearchResultsModel.swift index 357e82d..154daaa 100644 --- a/SwiftDiscogsApp/Search/DiscogsSearchResultsModel.swift +++ b/SwiftDiscogsApp/Search/DiscogsSearchResultsModel.swift @@ -30,13 +30,13 @@ class DiscogsSearchResultsModel: CollectionAndTableModel { } override func tableView(_ tableView: UITableView, - cellForRowAt indexPath: IndexPath) -> UITableViewCell { + cellForRowAt indexPath: IndexPath) -> UITableViewCell { let result = results?[indexPath.row] - + if let cell = tableView.dequeueReusableCell(withIdentifier: "artistSearchResultCell", for: indexPath) as? ArtistSearchResultCell { cell.searchResult = result - + return cell } else { return super.tableView(tableView, cellForRowAt: indexPath) @@ -47,6 +47,6 @@ class DiscogsSearchResultsModel: CollectionAndTableModel { public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return UITableView.automaticDimension - } + } } diff --git a/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift b/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift index c32928a..2bf2384 100644 --- a/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift +++ b/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift @@ -56,7 +56,7 @@ class DiscogsSearchViewController: CollectionAndTableViewController, public func search(forArtistNamed artistName: String) { searchController.searchBar.text = artistName } - + // MARK: UIViewController override func prepare(for segue: UIStoryboardSegue, sender: Any?) { diff --git a/SwiftDiscogsApp/SectionedModel.swift b/SwiftDiscogsApp/SectionedModel.swift index 60ee8bf..4e881ae 100644 --- a/SwiftDiscogsApp/SectionedModel.swift +++ b/SwiftDiscogsApp/SectionedModel.swift @@ -11,7 +11,7 @@ import UIKit open class SectionedModel: CollectionAndTableModel { // MARK: - Public Properties - + /// The sections that this model maintains. The order in which they're /// listed must match the order in which they'll appear in the table or /// collection view. Sections don't need to be unique *types*, but if @@ -20,13 +20,13 @@ open class SectionedModel: CollectionAndTableModel { public var sections: [Section] = [] // MARK: - Initialization - + /// Construct a model with no sections. This do-nothing initializer is /// required by the compiler for some reason. public override init() { super.init() } - + /// Construct a model with a list of `Section`s. These sections must be in /// the order in which they'll appear in the table or collection view. public init(sections: [Section]) { @@ -45,7 +45,7 @@ open class SectionedModel: CollectionAndTableModel { } // MARK: - Section - + /// A section of a table or collection view model. It provides the ID of /// cells in its section, as well as optional header text and custom header /// and footer views. @@ -53,11 +53,11 @@ open class SectionedModel: CollectionAndTableModel { open var cellID: String - open var footerView: UIView? = nil + open var footerView: UIView? - open var headerText: String? = nil + open var headerText: String? - open var headerView: UIView? = nil + open var headerView: UIView? public init(cellID: String, footerView: UIView? = nil, @@ -76,4 +76,3 @@ open class SectionedModel: CollectionAndTableModel { } } - diff --git a/SwiftDiscogsApp/Song/Song.swift b/SwiftDiscogsApp/Song/Song.swift index 0fcff93..8ef4613 100644 --- a/SwiftDiscogsApp/Song/Song.swift +++ b/SwiftDiscogsApp/Song/Song.swift @@ -14,7 +14,7 @@ open class Song: NSObject, Codable { open var lyrics: String? open var personnel: [Performer]? - + open var title: String open var versions: [Version] diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift index 4735f2b..e361250 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift @@ -42,11 +42,15 @@ public class DiscogsCollectionImporter: NSManagedObjectContext { private var discogsFolders = [SwiftDiscogs.CollectionFolder]() - public var importerDelegate: ImportableServiceDelegate? + public weak var importerDelegate: ImportableServiceDelegate? public weak var service: ImportableService? - private var importQueue = DispatchQueue(label: "DiscogsCollectionImporter", qos: .background, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil) + private var importQueue = DispatchQueue(label: "DiscogsCollectionImporter", + qos: .background, + attributes: .concurrent, + autoreleaseFrequency: .inherit, + target: nil) // MARK: - Import Functions @@ -58,7 +62,7 @@ public class DiscogsCollectionImporter: NSManagedObjectContext { self.importerDelegate?.update(importedItemCount: 1, totalCount: 6, forService: self.service) return self.createCoreDataFields(self.discogsFields) - }.then(on: importQueue) { (coreDataFields) -> Promise in + }.then(on: importQueue) { _ in self.importerDelegate?.update(importedItemCount: 2, totalCount: 6, forService: self.service) return self.discogs.collectionFolders(forUserName: userName) @@ -84,13 +88,13 @@ public class DiscogsCollectionImporter: NSManagedObjectContext { self.importerDelegate?.update(importedItemCount: 5, totalCount: 6, forService: self.service) return self.createCoreDataItems(forDiscogsItems: discogsItems) - }.then(on: importQueue) { (coreDataItemsByID) -> Promise in + }.then(on: importQueue) { _ in self.importerDelegate?.update(importedItemCount: 6, totalCount: 6, forService: self.service) return self.addCoreDataItemsToOtherFolders(forUserName: userName) - }.then(on: importQueue) { (emptyPromise) -> Promise in + }.then(on: importQueue) { _ in self.importerDelegate?.willFinishImporting(fromService: self.service) try self.save() - + return Promise() } } diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift index b5604c7..dbbd371 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift @@ -110,8 +110,8 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService // MARK: Properties /// Called when the user's Discogs collection is being imported. - var importDelegate: ImportableServiceDelegate? - + weak var importDelegate: ImportableServiceDelegate? + var isImporting: Bool = false // MARK: Functions @@ -150,5 +150,5 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService isImporting = false importDelegate?.didFinishImporting(fromService: self) } - + } diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsSignInViewController.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsSignInViewController.swift index 4538afe..29e1c7a 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsSignInViewController.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsSignInViewController.swift @@ -19,16 +19,16 @@ open class DiscogsSignInViewController: UIViewController { @IBOutlet weak var signInStatusStack: ToggleStackView! // MARK: - Actions - + /// Sign into the Discogs service, notifying the display when it's about to /// do so and after the user has logged in successfully. @IBAction func signInToDiscogs(signInButton: UIButton?) { signInStatusStack.activeView = checkingStatusView let promise = DiscogsManager.discogs.authorize(presentingViewController: self, callbackUrlString: AppDelegate.shared.callbackUrl.absoluteString) - promise.then { (credential) -> Promise in + promise.then { _ -> Promise in return DiscogsManager.discogs.userIdentity() - }.done { [weak self] (userIdentity) in + }.done { [weak self] _ in self?.signInStatusStack.activeView = self?.signedInLabel self?.dismiss(animated: true, completion: nil) }.catch { (error) in // not weak self because of Bundle(for:) diff --git a/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift b/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift index 7fe4e26..7b8d0b6 100644 --- a/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift +++ b/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift @@ -80,7 +80,7 @@ public protocol ImportableService: ThirdPartyService { /// `true` if the import process is currently in progress. var isImporting: Bool { get } - + // MARK: Functions /// Start importing data into a specified Core Data context. @@ -95,7 +95,7 @@ public protocol ImportableService: ThirdPartyService { /// Implemented by entities what want to keep track of an importable service's /// status and progress. -public protocol ImportableServiceDelegate { +public protocol ImportableServiceDelegate: class { // MARK: Functions @@ -118,4 +118,3 @@ public protocol ImportableServiceDelegate { func willFinishImporting(fromService: ImportableService?) } - diff --git a/SwiftDiscogsApp/Third-Party Services/ThirdPartyServicesViewController.swift b/SwiftDiscogsApp/Third-Party Services/ThirdPartyServicesViewController.swift index 57d5eb0..7af0059 100644 --- a/SwiftDiscogsApp/Third-Party Services/ThirdPartyServicesViewController.swift +++ b/SwiftDiscogsApp/Third-Party Services/ThirdPartyServicesViewController.swift @@ -3,7 +3,7 @@ import CoreData import UIKit -final class ThirdPartyServicesViewController: UITableViewController{ +final class ThirdPartyServicesViewController: UITableViewController { // MARK: - Properties diff --git a/SwiftDiscogsAppTests/Player/PlayerViewTests.swift b/SwiftDiscogsAppTests/Player/PlayerViewTests.swift index ca7aab0..2df76a5 100644 --- a/SwiftDiscogsAppTests/Player/PlayerViewTests.swift +++ b/SwiftDiscogsAppTests/Player/PlayerViewTests.swift @@ -32,7 +32,7 @@ class PlayerViewTests: XCTestCase { } // MARK: - PlayerButton tests - + func testInitialStateWithDefaultModel() { let model = PlayerModel() playerView.model = model @@ -79,7 +79,10 @@ class PlayerViewTests: XCTestCase { next: Bool, file: StaticString = #file, line: UInt = #line) { - XCTAssertEqual(buttonView.previousTrackButton!.isEnabled, previous, "Previous track button", file: file, line: line) + XCTAssertEqual(buttonView.previousTrackButton!.isEnabled, + previous, "Previous track button", + file: file, + line: line) XCTAssertEqual(buttonView.rewindButton!.isEnabled, rewind, "Rewind button", file: file, line: line) XCTAssertEqual(buttonView.playButton!.isEnabled, play, "Play button", file: file, line: line) XCTAssertEqual(buttonView.forwardButton!.isEnabled, forward, "Forward button", file: file, line: line) diff --git a/SwiftDiscogsAppTests/SectionedModelTests.swift b/SwiftDiscogsAppTests/SectionedModelTests.swift index e1bb9d8..824fbfb 100644 --- a/SwiftDiscogsAppTests/SectionedModelTests.swift +++ b/SwiftDiscogsAppTests/SectionedModelTests.swift @@ -8,11 +8,11 @@ class SectionedModelTests: XCTestCase { func testEmptyInitializerHasNoSections() { let model = SectionedModel() - + XCTAssertEqual(model.tableView.numberOfSections, 0) XCTAssertEqual(model.collectionView.numberOfSections , 0) } - + func testInitializerWith1Section() { let section = SectionedModel.Section(cellID: "section1CellID", headerText: "Section 1 Header Text") let model = SectionedModel(sections: [section]) @@ -22,16 +22,16 @@ class SectionedModelTests: XCTestCase { XCTAssertEqual(model.sections[0].cellID, "section1CellID") XCTAssertEqual(model.headerTitle(forSection: 0), "Section 1 Header Text") } - + } private extension SectionedModel { - + var collectionView: UICollectionView { return UICollectionView(frame: CGRect(), collectionViewLayout: UICollectionViewFlowLayout()) <~ { $0.dataSource = self } } - + var tableView: UITableView { return UITableView(frame: CGRect()) <~ { $0.dataSource = self} } diff --git a/SwiftDiscogsAppUITests/SwiftDiscogsAppUITests.swift b/SwiftDiscogsAppUITests/SwiftDiscogsAppUITests.swift index 54d66b2..07a8021 100644 --- a/SwiftDiscogsAppUITests/SwiftDiscogsAppUITests.swift +++ b/SwiftDiscogsAppUITests/SwiftDiscogsAppUITests.swift @@ -3,28 +3,34 @@ import XCTest class SwiftDiscogsAppUITests: XCTestCase { - + override func setUp() { super.setUp() - - // Put setup code here. This method is called before the invocation of each test method in the class. - - // In UI tests it is usually best to stop immediately when a failure occurs. + + // Put setup code here. This method is called before the invocation of + // each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure + // occurs. continueAfterFailure = false - // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. + // UI tests must launch the application that they test. Doing this in + // setup will make sure it happens for each test method. XCUIApplication().launch() - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + // In UI tests it’s important to set the initial state - such as + // interface orientation - required for your tests before they run. The setUp method is a good place to do this. } - + override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. + // Put teardown code here. This method is called after the invocation + // of each test method in the class. super.tearDown() } - + func testExample() { // Use recording to get started writing UI tests. - // Use XCTAssert and related functions to verify your tests produce the correct results. + // Use XCTAssert and related functions to verify your tests produce the + // correct results. } - + } diff --git a/Tests/ClientTestBase.swift b/Tests/ClientTestBase.swift index 159b798..f124dca 100644 --- a/Tests/ClientTestBase.swift +++ b/Tests/ClientTestBase.swift @@ -35,7 +35,7 @@ class ClientTestBase: JSONTestBase { let exp = expectation(description: description) var returnableError: Error? - promise.done { (fetchedObject) in + promise.done { _ in XCTFail("Expected an error to be thrown.", file: file, line: line) }.catch { (error) -> Void in returnableError = error diff --git a/Tests/Collection/CollectionCustomFieldsTests.swift b/Tests/Collection/CollectionCustomFieldsTests.swift index b3f3aa1..b32b30a 100644 --- a/Tests/Collection/CollectionCustomFieldsTests.swift +++ b/Tests/Collection/CollectionCustomFieldsTests.swift @@ -5,11 +5,11 @@ import JSONClient import XCTest class CollectionCustomFieldsTests: DiscogsTestBase { - + func testDecodeCollectionCustomFieldsJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-custom-fields-200")) } - + func assert(_ customFields: CollectionCustomFields, file: StaticString = #file, line: UInt = #line) { @@ -17,18 +17,18 @@ class CollectionCustomFieldsTests: DiscogsTestBase { XCTFail("The sample custom fields response JSON should include fields.", file: file, line: line) return } - + XCTAssertEqual(fields.count, 3, file: file, line: line) - + let mediaField = fields[0] XCTAssertEqual(mediaField.name, "Media", "field 0's name", file: file, line: line) XCTAssertEqual(mediaField.type, "dropdown", "field 0's type", file: file, line: line) XCTAssertEqual(mediaField.`public`, true, "field 0's public flag", file: file, line: line) - + let notesField = fields[2] XCTAssertEqual(notesField.name, "Notes", file: file, line: line) XCTAssertEqual(notesField.lines!, 3, file: file, line: line) XCTAssertEqual(notesField.type, "textarea", file: file, line: line) } - + } diff --git a/Tests/Collection/CollectionFolderItemsTests.swift b/Tests/Collection/CollectionFolderItemsTests.swift index 0a5944f..ea09f04 100644 --- a/Tests/Collection/CollectionFolderItemsTests.swift +++ b/Tests/Collection/CollectionFolderItemsTests.swift @@ -4,11 +4,11 @@ import XCTest class CollectionFolderItemsTests: DiscogsTestBase { - + func testDecodeCollectionValueJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-items-in-folder-200")) } - + func assert(_ items: CollectionFolderItems, file: StaticString = #file, line: UInt = #line) { @@ -16,9 +16,8 @@ class CollectionFolderItemsTests: DiscogsTestBase { XCTFail("The folder item's releases array shouldn't be nil.", file: file, line: line) return } - + XCTAssertEqual(releases.count, 2) } - -} +} diff --git a/Tests/Collection/CollectionItemInfoTests.swift b/Tests/Collection/CollectionItemInfoTests.swift index fc993ef..9e78322 100644 --- a/Tests/Collection/CollectionItemInfoTests.swift +++ b/Tests/Collection/CollectionItemInfoTests.swift @@ -4,11 +4,11 @@ import XCTest class CollectionItemInfoTests: DiscogsTestBase { - + func testDecodeCollectionItemInfoJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "add-item-to-collection-folder-200")) } - + func assert(_ item: CollectionItemInfo, file: StaticString = #file, line: UInt = #line) { @@ -18,6 +18,5 @@ class CollectionItemInfoTests: DiscogsTestBase { file: file, line: line) } - -} +} diff --git a/Tests/Collection/CollectionValueTests.swift b/Tests/Collection/CollectionValueTests.swift index 23daad7..51468ae 100644 --- a/Tests/Collection/CollectionValueTests.swift +++ b/Tests/Collection/CollectionValueTests.swift @@ -5,17 +5,17 @@ import JSONClient import XCTest class CollectionValueTests: DiscogsTestBase { - + func testDecodeCollectionValueJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-collection-value-200")) } - + func assert(_ collectionValue: CollectionValue, file: StaticString = #file, line: UInt = #line) { - XCTAssertEqual(collectionValue.minimum, "$75.50", file: file, line: line) - XCTAssertEqual(collectionValue.median, "$100.25", file: file, line: line) + XCTAssertEqual(collectionValue.minimum, "$75.50", file: file, line: line) + XCTAssertEqual(collectionValue.median, "$100.25", file: file, line: line) XCTAssertEqual(collectionValue.maximum, "$250.00", file: file, line: line) } - + } diff --git a/Tests/Database/ArtistTests.swift b/Tests/Database/ArtistTests.swift index 7e38cd5..212ed65 100644 --- a/Tests/Database/ArtistTests.swift +++ b/Tests/Database/ArtistTests.swift @@ -4,15 +4,15 @@ import XCTest class ArtistTests: DiscogsTestBase { - + func testDecodeArtistJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-artist-200")) } - + func testGetArtistNotFoundError() { assertDiscogsErrorMessage(in: "get-artist-404", is: "Artist not found.") } - + func assert(_ artist: Artist, file: StaticString = #file, line: UInt = #line) { @@ -20,11 +20,11 @@ class ArtistTests: DiscogsTestBase { XCTAssertEqual(artist.namevariations![0], "Nickleback", "artist name", file: file, line: line) XCTAssertEqual(artist.images!.count, 2, "artist images", file: file, line: line) XCTAssertEqual(artist.members!.count, 5, "band members", file: file, line: line) - + let shittyMember = artist.members![0] XCTAssertEqual(shittyMember.active, true, "is band member still active", file: file, line: line) XCTAssertEqual(shittyMember.id, 270222, "band member ID", file: file, line: line) XCTAssertEqual(shittyMember.name, "Chad Kroeger", file: file, line: line) } - + } diff --git a/Tests/Database/LabelReleasesTests.swift b/Tests/Database/LabelReleasesTests.swift index 56ccbdc..d264466 100644 --- a/Tests/Database/LabelReleasesTests.swift +++ b/Tests/Database/LabelReleasesTests.swift @@ -4,15 +4,15 @@ import XCTest class LabelReleasesTests: DiscogsTestBase { - + func testDiscogsLabelReleasesJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-label-releases-200")) } - + func testGetLabelReleasesNotFoundError() { assertDiscogsErrorMessage(in: "get-label-releases-404", is: "Label not found.") } - + func assert(_ labelReleases: ReleaseSummaries, file: StaticString = #file, line: UInt = #line) { @@ -20,10 +20,9 @@ class LabelReleasesTests: DiscogsTestBase { XCTFail("There should be at least 3 releases in the file.", file: file, line: line) return } - + XCTAssertEqual(release3.artist, "Innerzone Orchestra", "release artist name", file: file, line: line) XCTAssertEqual(release3.year, 1999, "release year", file: file, line: line) } - -} +} diff --git a/Tests/Database/LabelTests.swift b/Tests/Database/LabelTests.swift index 032e81a..d48aaca 100644 --- a/Tests/Database/LabelTests.swift +++ b/Tests/Database/LabelTests.swift @@ -4,20 +4,20 @@ import XCTest class LabelTests: DiscogsTestBase { - + func testDiscogsLabelJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-label-200")) } - + func testGetLabelNotFoundError() { assertDiscogsErrorMessage(in: "get-label-404", is: "Label not found.") } - + func assert(_ label: RecordLabel, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(label.name, "Planet E", "label name", file: file, line: line) XCTAssertEqual(label.sublabels?.count, 2, file: file, line: line) } - + } diff --git a/Tests/Database/MasterReleaseTests.swift b/Tests/Database/MasterReleaseTests.swift index 000966d..2500e68 100644 --- a/Tests/Database/MasterReleaseTests.swift +++ b/Tests/Database/MasterReleaseTests.swift @@ -4,20 +4,20 @@ import XCTest class MasterReleaseTests: DiscogsTestBase { - + func testDecodeMasterReleaseJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-master-200")) } - + func testGetMasterReleaseNotFoundError() { assertDiscogsErrorMessage(in: "get-master-404", is: "Master Release not found.") } - + func assert(_ masterRelease: MasterRelease, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(masterRelease.title, "Stardiver", file: file, line: line) XCTAssertEqual(masterRelease.year, 1997, file: file, line: line) } - + } diff --git a/Tests/Database/ReleaseSummaryTests.swift b/Tests/Database/ReleaseSummaryTests.swift index 158c472..a2a8f9f 100644 --- a/Tests/Database/ReleaseSummaryTests.swift +++ b/Tests/Database/ReleaseSummaryTests.swift @@ -4,7 +4,7 @@ import XCTest class ReleaseSummaryTests: DiscogsTestBase { - + func testDecodeArtistReleasesJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-release-summaries-200")) } @@ -25,7 +25,7 @@ class ReleaseSummaryTests: DiscogsTestBase { XCTFail("The release should have had 2 formats.") } } - + func testGetArtistReleasesNotFoundError() { assertDiscogsErrorMessage(in: "get-release-summaries-404", is: "Artist not found.") } @@ -58,5 +58,5 @@ class ReleaseSummaryTests: DiscogsTestBase { XCTFail("Release 2 should have CD & EP formats", file: file, line: line) } } - + } diff --git a/Tests/Database/ReleaseTests.swift b/Tests/Database/ReleaseTests.swift index 909a54c..23be739 100644 --- a/Tests/Database/ReleaseTests.swift +++ b/Tests/Database/ReleaseTests.swift @@ -4,15 +4,15 @@ import XCTest class ReleaseTests: DiscogsTestBase { - + func testDecodeReleaseJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-release-200")) } - + func testGetReleaseNotFoundError() { assertDiscogsErrorMessage(in: "get-release-404", is: "Release not found.") } - + func assert(_ releaseVersion: Release, file: StaticString = #file, line: UInt = #line) { @@ -23,6 +23,5 @@ class ReleaseTests: DiscogsTestBase { file: file, line: line) } - -} +} diff --git a/Tests/DiscogsClientTests.swift b/Tests/DiscogsClientTests.swift index 0681152..a6b775b 100644 --- a/Tests/DiscogsClientTests.swift +++ b/Tests/DiscogsClientTests.swift @@ -32,7 +32,7 @@ class DiscogsClientTests: DiscogsTestBase { promise.done { (artist) in XCTAssertEqual(artist.name, "Sinéad O'Connor") exp.fulfill() - }.catch { (error) in + }.catch { _ in XCTFail(failureMessage) } @@ -44,9 +44,9 @@ class DiscogsClientTests: DiscogsTestBase { let failureMessage = "Expected Discogs artist \(artistId) to be invalid" let exp = expectation(description: failureMessage) let promise: Promise = unauthorizedClient.artist(identifier: artistId) - promise.done { (artist) in + promise.done { _ in XCTFail(failureMessage) - }.catch { (error) in + }.catch { _ in exp.fulfill() } @@ -73,9 +73,9 @@ class DiscogsClientTests: DiscogsTestBase { let failureMessage = "Expected Discogs label \(labelId) to be invalid" let exp = expectation(description: failureMessage) let promise: Promise = unauthorizedClient.artist(identifier: labelId) - promise.done { (label) in + promise.done { _ in XCTFail(failureMessage) - }.catch { (error) in + }.catch { _ in exp.fulfill() } @@ -92,7 +92,7 @@ class DiscogsClientTests: DiscogsTestBase { XCTAssertEqual(masterRelease.id, masterId) XCTAssertEqual(masterRelease.year, 1987) exp.fulfill() - }.catch { (error) in + }.catch { _ in XCTFail(failureMessage) } wait(for: [exp], timeout: 5.0) @@ -103,9 +103,9 @@ class DiscogsClientTests: DiscogsTestBase { let failureMessage = "Expected Discogs master release \(masterId) to be invalid" let exp = expectation(description: failureMessage) let promise: Promise = unauthorizedClient.masterRelease(identifier: masterId) - promise.done { (masterRelease) in + promise.done { _ in XCTFail(failureMessage) - }.catch { (error) in + }.catch { _ in exp.fulfill() } wait(for: [exp], timeout: 5.0) @@ -121,7 +121,7 @@ class DiscogsClientTests: DiscogsTestBase { XCTAssertEqual(release.id, releaseId) XCTAssertEqual(release.year, 1987) exp.fulfill() - }.catch { (error) in + }.catch { _ in XCTFail(failureMessage) } wait(for: [exp], timeout: 5.0) @@ -132,9 +132,9 @@ class DiscogsClientTests: DiscogsTestBase { let failureMessage = "Expected Discogs release \(releaseId) to be invalid" let exp = expectation(description: failureMessage) let promise: Promise = unauthorizedClient.release(identifier: releaseId) - promise.done { (release) in + promise.done { _ in XCTFail(failureMessage) - }.catch { (error) in + }.catch { _ in exp.fulfill() } wait(for: [exp], timeout: 5.0) @@ -149,7 +149,7 @@ class DiscogsClientTests: DiscogsTestBase { XCTAssertNotNil(summaries.pagination) XCTAssertTrue(summaries.pagination!.items >= 116) exp.fulfill() - }.catch { (error) in + }.catch { _ in XCTFail(failureMessage) } wait(for: [exp], timeout: 5.0) @@ -160,9 +160,9 @@ class DiscogsClientTests: DiscogsTestBase { let failureMessage = "Expected Discogs artist \(artistId) to be invalid" let exp = expectation(description: failureMessage) let promise: Promise = unauthorizedClient.releases(forArtist: artistId) - promise.done { (summaries) in + promise.done { _ in XCTFail(failureMessage) - }.catch { (error) in + }.catch { _ in exp.fulfill() } wait(for: [exp], timeout: 5.0) @@ -177,7 +177,7 @@ class DiscogsClientTests: DiscogsTestBase { XCTAssertNotNil(summaries.pagination) XCTAssertTrue(summaries.pagination!.items >= 16000) exp.fulfill() - }.catch { (error) in + }.catch { _ in XCTFail(failureMessage) } wait(for: [exp], timeout: 5.0) @@ -188,9 +188,9 @@ class DiscogsClientTests: DiscogsTestBase { let failureMessage = "Expected Discogs label \(labelId) to be invalid" let exp = expectation(description: failureMessage) let promise: Promise = unauthorizedClient.releases(forLabel: labelId) - promise.done { (summaries) in + promise.done { _ in XCTFail(failureMessage) - }.catch { (error) in + }.catch { _ in exp.fulfill() } wait(for: [exp], timeout: 5.0) @@ -205,7 +205,7 @@ class DiscogsClientTests: DiscogsTestBase { XCTAssertNotNil(summaries.pagination) XCTAssertTrue(summaries.pagination!.items >= 20) exp.fulfill() - }.catch { (error) in + }.catch { _ in XCTFail(failureMessage) } wait(for: [exp], timeout: 5.0) @@ -229,12 +229,14 @@ class DiscogsClientTests: DiscogsTestBase { } func testCollectionFolderInfoBeforeAuthenticationFails() { - let promise: Promise = unauthorizedClient.collectionFolderInfo(forFolderID: 99, userName: "foo") + let promise: Promise + = unauthorizedClient.collectionFolderInfo(forFolderID: 99, userName: "foo") assertUnauthorizedCallFails(promise: promise, description: "collection folder info") } func testCollectionFolderItemsBeforeAuthenticationFails() { - let promise: Promise = unauthorizedClient.collectionItems(inFolderID: 99, userName: "foo") + let promise: Promise + = unauthorizedClient.collectionItems(inFolderID: 99, userName: "foo") assertUnauthorizedCallFails(promise: promise, description: "collection items") } @@ -242,9 +244,9 @@ class DiscogsClientTests: DiscogsTestBase { description: String) { let exp = expectation(description: "The call should fail if the caller hasn't authenticated yet") - promise.done { (fields) in + promise.done { _ in XCTFail("\(description) should have failed if the caller hasn't authenticated yet.") - }.catch { (error) in + }.catch { _ in exp.fulfill() } diff --git a/Tests/DiscogsTestBase.swift b/Tests/DiscogsTestBase.swift index 676c508..9a9b04d 100644 --- a/Tests/DiscogsTestBase.swift +++ b/Tests/DiscogsTestBase.swift @@ -35,5 +35,5 @@ class DiscogsTestBase: ClientTestBase { XCTFail("Failed to assert the error message; got \"\(error.localizedDescription)\" instead.") } } - + } diff --git a/Tests/JSONTestBase.swift b/Tests/JSONTestBase.swift index 2cfca8d..2c15104 100644 --- a/Tests/JSONTestBase.swift +++ b/Tests/JSONTestBase.swift @@ -22,4 +22,3 @@ public class JSONTestBase: XCTestCase { } } - diff --git a/Tests/User Identity/UserIdentityTests.swift b/Tests/User Identity/UserIdentityTests.swift index f1d2314..9643f4f 100644 --- a/Tests/User Identity/UserIdentityTests.swift +++ b/Tests/User Identity/UserIdentityTests.swift @@ -2,15 +2,15 @@ import XCTest class UserIdentityTests: DiscogsTestBase { - + func testDecodeUserIdentityJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-user-identity-200")) } - + func testGetUserIdentityUnauthorizedError() { assertDiscogsErrorMessage(in: "get-user-identity-401", is: "You must authenticate to access this resource.") } - + func assert(_ userIdentity: UserIdentity, file: StaticString = #file, line: UInt = #line) { @@ -18,5 +18,5 @@ class UserIdentityTests: DiscogsTestBase { XCTAssertEqual("example", userIdentity.username, file: file, line: line) XCTAssertEqual("Your Application Name", userIdentity.consumerName, file: file, line: line) } - + } diff --git a/Tests/User Identity/UserProfileTests.swift b/Tests/User Identity/UserProfileTests.swift index 8c24dc0..363c771 100644 --- a/Tests/User Identity/UserProfileTests.swift +++ b/Tests/User Identity/UserProfileTests.swift @@ -4,11 +4,11 @@ import XCTest class UserProfileTests: DiscogsTestBase { - + func testDecodeUserProfileJson() throws { assert(try discogsObject(inLocalJsonFileNamed: "get-user-profile-200")) } - + func assert(_ userProfile: UserProfile, file: StaticString = #file, line: UInt = #line) { @@ -16,5 +16,5 @@ class UserProfileTests: DiscogsTestBase { XCTAssertEqual("2012-08-15T21:13:36-07:00", userProfile.registered, file: file, line: line) XCTAssertEqual(100, userProfile.buyerRating, file: file, line: line) } - + }