From 3bc25449b0973d4757a4c89c4507ccdf6fc78f6d Mon Sep 17 00:00:00 2001 From: Chris Araman Date: Sun, 21 Mar 2021 22:46:17 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Lint=20with=20swiftformat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftformat | 5 +++-- MasKit/AppStore/CKSoftwareMap+SoftwareMap.swift | 4 ++-- MasKit/AppStore/ISStoreAccount.swift | 2 +- MasKit/AppStore/PurchaseDownloadObserver.swift | 4 ++-- MasKit/AppStore/SSPurchase.swift | 2 +- MasKit/Commands/Account.swift | 2 +- MasKit/Commands/Home.swift | 6 +++--- MasKit/Commands/Info.swift | 6 +++--- MasKit/Commands/Install.swift | 6 +++--- MasKit/Commands/List.swift | 2 +- MasKit/Commands/Lucky.swift | 8 ++++---- MasKit/Commands/Open.swift | 6 +++--- MasKit/Commands/Outdated.swift | 2 +- MasKit/Commands/Purchase.swift | 6 +++--- MasKit/Commands/Reset.swift | 6 +++--- MasKit/Commands/Search.swift | 6 +++--- MasKit/Commands/SignIn.swift | 4 ++-- MasKit/Commands/SignOut.swift | 2 +- MasKit/Commands/Uninstall.swift | 6 +++--- MasKit/Commands/Upgrade.swift | 6 +++--- MasKit/Commands/Vendor.swift | 6 +++--- MasKit/Commands/Version.swift | 2 +- MasKit/Controllers/AppLibrary.swift | 2 +- MasKit/Controllers/MasAppLibrary.swift | 6 +++--- MasKit/Controllers/StoreSearch.swift | 2 +- MasKit/Extensions/Dictionary+StringOrEmpty.swift | 2 +- MasKit/Extensions/String+PercentEncoding.swift | 6 +++--- MasKit/ExternalCommands/ExternalCommand.swift | 6 +++--- MasKit/Formatters/AppListFormatter.swift | 3 +-- MasKit/Formatters/SearchResultFormatter.swift | 2 +- MasKit/Models/SoftwareProduct.swift | 2 +- MasKitTests/Controllers/AppLibraryMock.swift | 2 +- MasKitTests/Controllers/MasAppLibrarySpec.swift | 5 +++-- MasKitTests/Controllers/StoreSearchSpec.swift | 4 ++-- MasKitTests/Errors/MASErrorTestCase.swift | 2 +- MasKitTests/Extensions/Bundle+JSON.swift | 5 +++-- MasKitTests/Extensions/String+FileExtension.swift | 4 ++-- MasKitTests/ExternalCommands/OpenSystemCommandSpec.swift | 1 - MasKitTests/Network/TestURLSessionDelegate.swift | 2 +- MasKitTests/Nimble/ResultPredicates.swift | 8 ++++---- MasKitTests/OutputListener.swift | 4 ++-- MasKitTests/Strongify.swift | 4 +++- script/lint | 1 + 43 files changed, 88 insertions(+), 84 deletions(-) diff --git a/.swiftformat b/.swiftformat index 54a1b23..10bf263 100644 --- a/.swiftformat +++ b/.swiftformat @@ -14,6 +14,7 @@ --enable trailingClosures # Rule options ---commas inline ---guardelse same-line +--commas always +--extensionacl on-declarations --importgrouping testable-last +--ranges no-space diff --git a/MasKit/AppStore/CKSoftwareMap+SoftwareMap.swift b/MasKit/AppStore/CKSoftwareMap+SoftwareMap.swift index a5b3f6d..5993e4d 100644 --- a/MasKit/AppStore/CKSoftwareMap+SoftwareMap.swift +++ b/MasKit/AppStore/CKSoftwareMap+SoftwareMap.swift @@ -11,10 +11,10 @@ import CommerceKit // MARK: - SoftwareProduct extension CKSoftwareMap: SoftwareMap { func allSoftwareProducts() -> [SoftwareProduct] { - return allProducts() ?? [] + allProducts() ?? [] } func product(for bundleIdentifier: String) -> SoftwareProduct? { - return product(forBundleIdentifier: bundleIdentifier) + product(forBundleIdentifier: bundleIdentifier) } } diff --git a/MasKit/AppStore/ISStoreAccount.swift b/MasKit/AppStore/ISStoreAccount.swift index e2211a4..8f0d0a9 100644 --- a/MasKit/AppStore/ISStoreAccount.swift +++ b/MasKit/AppStore/ISStoreAccount.swift @@ -11,7 +11,7 @@ import StoreFoundation extension ISStoreAccount: StoreAccount { static var primaryAccountIsPresentAndSignedIn: Bool { - return CKAccountStore.shared().primaryAccountIsPresentAndSignedIn + CKAccountStore.shared().primaryAccountIsPresentAndSignedIn } static var primaryAccount: StoreAccount? { diff --git a/MasKit/AppStore/PurchaseDownloadObserver.swift b/MasKit/AppStore/PurchaseDownloadObserver.swift index a82a9b7..2f49708 100644 --- a/MasKit/AppStore/PurchaseDownloadObserver.swift +++ b/MasKit/AppStore/PurchaseDownloadObserver.swift @@ -64,7 +64,7 @@ struct ProgressState { let phase: String var percentage: String { - return String(format: "%.1f%%", arguments: [floor(percentComplete * 100)]) + String(format: "%.1f%%", arguments: [floor(percentComplete * 100)]) } } @@ -92,7 +92,7 @@ func progress(_ state: ProgressState) { extension SSDownloadStatus { var progressState: ProgressState { - return ProgressState(percentComplete: percentComplete, phase: activePhase.phaseDescription) + ProgressState(percentComplete: percentComplete, phase: activePhase.phaseDescription) } } diff --git a/MasKit/AppStore/SSPurchase.swift b/MasKit/AppStore/SSPurchase.swift index 533804b..4876f61 100644 --- a/MasKit/AppStore/SSPurchase.swift +++ b/MasKit/AppStore/SSPurchase.swift @@ -35,7 +35,7 @@ extension SSPurchase { buyParameters = parameters.map { key, value in - return "\(key)=\(value)" + "\(key)=\(value)" } .joined(separator: "&") diff --git a/MasKit/Commands/Account.swift b/MasKit/Commands/Account.swift index 5891076..26044df 100644 --- a/MasKit/Commands/Account.swift +++ b/MasKit/Commands/Account.swift @@ -17,7 +17,7 @@ public struct AccountCommand: CommandProtocol { public init() {} /// Runs the command. - public func run(_: Options) -> Result<(), MASError> { + public func run(_: Options) -> Result { if let account = ISStoreAccount.primaryAccount { print(String(describing: account.identifier)) } else { diff --git a/MasKit/Commands/Home.swift b/MasKit/Commands/Home.swift index 3c80b85..47abe28 100644 --- a/MasKit/Commands/Home.swift +++ b/MasKit/Commands/Home.swift @@ -29,7 +29,7 @@ public struct HomeCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: HomeOptions) -> Result<(), MASError> { + public func run(_ options: HomeOptions) -> Result { do { guard let result = try storeSearch.lookup(app: options.appId) else { print("No results found") @@ -63,11 +63,11 @@ public struct HomeOptions: OptionsProtocol { let appId: Int static func create(_ appId: Int) -> HomeOptions { - return HomeOptions(appId: appId) + HomeOptions(appId: appId) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "ID of app to show on MAS Preview") } } diff --git a/MasKit/Commands/Info.swift b/MasKit/Commands/Info.swift index d6e1726..61a3185 100644 --- a/MasKit/Commands/Info.swift +++ b/MasKit/Commands/Info.swift @@ -23,7 +23,7 @@ public struct InfoCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: InfoOptions) -> Result<(), MASError> { + public func run(_ options: InfoOptions) -> Result { do { guard let result = try storeSearch.lookup(app: options.appId) else { print("No results found") @@ -47,11 +47,11 @@ public struct InfoOptions: OptionsProtocol { let appId: Int static func create(_ appId: Int) -> InfoOptions { - return InfoOptions(appId: appId) + InfoOptions(appId: appId) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "ID of app to show info") } } diff --git a/MasKit/Commands/Install.swift b/MasKit/Commands/Install.swift index f16db8b..92e6968 100644 --- a/MasKit/Commands/Install.swift +++ b/MasKit/Commands/Install.swift @@ -29,7 +29,7 @@ public struct InstallCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { // Try to download applications with given identifiers and collect results let downloadResults = options.appIds.compactMap { (appId) -> MASError? in if let product = appLibrary.installedApp(forId: appId), !options.forceInstall { @@ -56,13 +56,13 @@ public struct InstallOptions: OptionsProtocol { let forceInstall: Bool public static func create(_ appIds: [Int]) -> (_ forceInstall: Bool) -> InstallOptions { - return { forceInstall in + { forceInstall in InstallOptions(appIds: appIds.map { UInt64($0) }, forceInstall: forceInstall) } } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "app ID(s) to install") <*> mode <| Switch(flag: nil, key: "force", usage: "force reinstall") } diff --git a/MasKit/Commands/List.swift b/MasKit/Commands/List.swift index 7665fe8..e041e81 100644 --- a/MasKit/Commands/List.swift +++ b/MasKit/Commands/List.swift @@ -29,7 +29,7 @@ public struct ListCommand: CommandProtocol { } /// Runs the command. - public func run(_: Options) -> Result<(), MASError> { + public func run(_: Options) -> Result { let products = appLibrary.installedApps if products.isEmpty { print("No installed apps found") diff --git a/MasKit/Commands/Lucky.swift b/MasKit/Commands/Lucky.swift index 25f957c..520ac86 100644 --- a/MasKit/Commands/Lucky.swift +++ b/MasKit/Commands/Lucky.swift @@ -37,7 +37,7 @@ public struct LuckyCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { var appId: Int? do { @@ -67,7 +67,7 @@ public struct LuckyCommand: CommandProtocol { /// - appId: App identifier /// - options: command opetions. /// - Returns: Result of the operation. - fileprivate func install(_ appId: UInt64, options: Options) -> Result<(), MASError> { + fileprivate func install(_ appId: UInt64, options: Options) -> Result { // Try to download applications with given identifiers and collect results let downloadResults = [appId] .compactMap { (appId) -> MASError? in @@ -95,13 +95,13 @@ public struct LuckyOptions: OptionsProtocol { let forceInstall: Bool public static func create(_ appName: String) -> (_ forceInstall: Bool) -> LuckyOptions { - return { forceInstall in + { forceInstall in LuckyOptions(appName: appName, forceInstall: forceInstall) } } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "the app name to install") <*> mode <| Switch(flag: nil, key: "force", usage: "force reinstall") } diff --git a/MasKit/Commands/Open.swift b/MasKit/Commands/Open.swift index 236733e..5c00ac8 100644 --- a/MasKit/Commands/Open.swift +++ b/MasKit/Commands/Open.swift @@ -32,7 +32,7 @@ public struct OpenCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: OpenOptions) -> Result<(), MASError> { + public func run(_ options: OpenOptions) -> Result { do { if options.appId == markerValue { // If no app ID is given, just open the MAS GUI app @@ -85,11 +85,11 @@ public struct OpenOptions: OptionsProtocol { var appId: String static func create(_ appId: String) -> OpenOptions { - return OpenOptions(appId: appId) + OpenOptions(appId: appId) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(defaultValue: markerValue, usage: "the app ID") } } diff --git a/MasKit/Commands/Outdated.swift b/MasKit/Commands/Outdated.swift index 4e54fd4..2e80ed1 100644 --- a/MasKit/Commands/Outdated.swift +++ b/MasKit/Commands/Outdated.swift @@ -32,7 +32,7 @@ public struct OutdatedCommand: CommandProtocol { } /// Runs the command. - public func run(_: Options) -> Result<(), MASError> { + public func run(_: Options) -> Result { for installedApp in appLibrary.installedApps { do { if let storeApp = try storeSearch.lookup(app: installedApp.itemIdentifier.intValue) { diff --git a/MasKit/Commands/Purchase.swift b/MasKit/Commands/Purchase.swift index 3282d72..40b80ae 100644 --- a/MasKit/Commands/Purchase.swift +++ b/MasKit/Commands/Purchase.swift @@ -28,7 +28,7 @@ public struct PurchaseCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { // Try to download applications with given identifiers and collect results let downloadResults = options.appIds.compactMap { (appId) -> MASError? in if let product = appLibrary.installedApp(forId: appId) { @@ -54,11 +54,11 @@ public struct PurchaseOptions: OptionsProtocol { let appIds: [UInt64] public static func create(_ appIds: [Int]) -> PurchaseOptions { - return PurchaseOptions(appIds: appIds.map { UInt64($0) }) + PurchaseOptions(appIds: appIds.map { UInt64($0) }) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "app ID(s) to install") } } diff --git a/MasKit/Commands/Reset.swift b/MasKit/Commands/Reset.swift index e31f0de..b2ffd25 100644 --- a/MasKit/Commands/Reset.swift +++ b/MasKit/Commands/Reset.swift @@ -18,7 +18,7 @@ public struct ResetCommand: CommandProtocol { public init() {} /// Runs the command. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { /* The "Reset Application" command in the Mac App Store debug menu performs the following steps @@ -83,11 +83,11 @@ public struct ResetOptions: OptionsProtocol { let debug: Bool public static func create(debug: Bool) -> ResetOptions { - return ResetOptions(debug: debug) + ResetOptions(debug: debug) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Switch(flag: nil, key: "debug", usage: "Enable debug mode") } } diff --git a/MasKit/Commands/Search.swift b/MasKit/Commands/Search.swift index 94f8556..f3bd86f 100644 --- a/MasKit/Commands/Search.swift +++ b/MasKit/Commands/Search.swift @@ -24,7 +24,7 @@ public struct SearchCommand: CommandProtocol { self.storeSearch = storeSearch } - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { do { let resultList = try storeSearch.search(for: options.appName) if resultList.resultCount <= 0 || resultList.results.isEmpty { @@ -51,13 +51,13 @@ public struct SearchOptions: OptionsProtocol { let price: Bool public static func create(_ appName: String) -> (_ price: Bool) -> SearchOptions { - return { price in + { price in SearchOptions(appName: appName, price: price) } } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "the app name to search") <*> mode <| Option(key: "price", defaultValue: false, usage: "Show price of found apps") } diff --git a/MasKit/Commands/SignIn.swift b/MasKit/Commands/SignIn.swift index ea5ac9b..bb595f4 100644 --- a/MasKit/Commands/SignIn.swift +++ b/MasKit/Commands/SignIn.swift @@ -18,7 +18,7 @@ public struct SignInCommand: CommandProtocol { public init() {} /// Runs the command. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { if #available(macOS 10.13, *) { return .failure(.signInDisabled) } @@ -58,7 +58,7 @@ public struct SignInOptions: OptionsProtocol { } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "Apple ID") <*> mode <| Argument(defaultValue: "", usage: "Password") <*> mode <| Option(key: "dialog", defaultValue: false, usage: "Complete login with graphical dialog") diff --git a/MasKit/Commands/SignOut.swift b/MasKit/Commands/SignOut.swift index 40e9822..efdf467 100644 --- a/MasKit/Commands/SignOut.swift +++ b/MasKit/Commands/SignOut.swift @@ -17,7 +17,7 @@ public struct SignOutCommand: CommandProtocol { public init() {} /// Runs the command. - public func run(_: Options) -> Result<(), MASError> { + public func run(_: Options) -> Result { if #available(macOS 10.13, *) { let accountService: ISAccountService = ISServiceProxy.genericShared().accountService accountService.signOut() diff --git a/MasKit/Commands/Uninstall.swift b/MasKit/Commands/Uninstall.swift index eee9d1e..ebf0111 100644 --- a/MasKit/Commands/Uninstall.swift +++ b/MasKit/Commands/Uninstall.swift @@ -34,7 +34,7 @@ public struct UninstallCommand: CommandProtocol { /// /// - Parameter options: UninstallOptions (arguments) for this command /// - Returns: Success or an error. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { let appId = UInt64(options.appId) guard let product = appLibrary.installedApp(forId: appId) else { @@ -67,13 +67,13 @@ public struct UninstallOptions: OptionsProtocol { let dryRun: Bool static func create(_ appId: Int) -> (_ dryRun: Bool) -> UninstallOptions { - return { dryRun in + { dryRun in UninstallOptions(appId: appId, dryRun: dryRun) } } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "ID of app to uninstall") <*> mode <| Switch(flag: nil, key: "dry-run", usage: "dry run") } diff --git a/MasKit/Commands/Upgrade.swift b/MasKit/Commands/Upgrade.swift index 6a3f27f..bb260bb 100644 --- a/MasKit/Commands/Upgrade.swift +++ b/MasKit/Commands/Upgrade.swift @@ -31,7 +31,7 @@ public struct UpgradeCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: Options) -> Result<(), MASError> { + public func run(_ options: Options) -> Result { do { let apps = try @@ -99,11 +99,11 @@ public struct UpgradeOptions: OptionsProtocol { let apps: [String] static func create(_ apps: [String]) -> UpgradeOptions { - return UpgradeOptions(apps: apps) + UpgradeOptions(apps: apps) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(defaultValue: [], usage: "app(s) to upgrade") } } diff --git a/MasKit/Commands/Vendor.swift b/MasKit/Commands/Vendor.swift index b53df06..8fa0ce5 100644 --- a/MasKit/Commands/Vendor.swift +++ b/MasKit/Commands/Vendor.swift @@ -29,7 +29,7 @@ public struct VendorCommand: CommandProtocol { } /// Runs the command. - public func run(_ options: VendorOptions) -> Result<(), MASError> { + public func run(_ options: VendorOptions) -> Result { do { guard let result = try storeSearch.lookup(app: options.appId) else { @@ -67,11 +67,11 @@ public struct VendorOptions: OptionsProtocol { let appId: Int static func create(_ appId: Int) -> VendorOptions { - return VendorOptions(appId: appId) + VendorOptions(appId: appId) } public static func evaluate(_ mode: CommandMode) -> Result> { - return create + create <*> mode <| Argument(usage: "the app ID to show the vendor's website") } } diff --git a/MasKit/Commands/Version.swift b/MasKit/Commands/Version.swift index d468436..bdf3c60 100644 --- a/MasKit/Commands/Version.swift +++ b/MasKit/Commands/Version.swift @@ -17,7 +17,7 @@ public struct VersionCommand: CommandProtocol { public init() {} /// Runs the command. - public func run(_: Options) -> Result<(), MASError> { + public func run(_: Options) -> Result { let plist = Bundle.main.infoDictionary if let versionString = plist?["CFBundleShortVersionString"] { print(versionString) diff --git a/MasKit/Controllers/AppLibrary.swift b/MasKit/Controllers/AppLibrary.swift index 26f5ef4..ab6d28e 100644 --- a/MasKit/Controllers/AppLibrary.swift +++ b/MasKit/Controllers/AppLibrary.swift @@ -64,6 +64,6 @@ extension AppLibrary { /// - Parameter appName: Full title of an app. /// - Returns: Software Product of app if found; nil otherwise. public func installedApp(named appName: String) -> SoftwareProduct? { - return installedApps.first { $0.appName == appName } + installedApps.first { $0.appName == appName } } } diff --git a/MasKit/Controllers/MasAppLibrary.swift b/MasKit/Controllers/MasAppLibrary.swift index 705ab81..c1bc8fc 100644 --- a/MasKit/Controllers/MasAppLibrary.swift +++ b/MasKit/Controllers/MasAppLibrary.swift @@ -15,7 +15,7 @@ public class MasAppLibrary: AppLibrary { /// Array of installed software products. public lazy var installedApps: [SoftwareProduct] = { - return softwareMap.allSoftwareProducts() + softwareMap.allSoftwareProducts() }() /// Internal initializer for providing a mock software map. @@ -29,7 +29,7 @@ public class MasAppLibrary: AppLibrary { /// - Parameter bundleId: Bundle identifier of app. /// - Returns: Software Product of app if found; nil otherwise. public func installedApp(forBundleId bundleId: String) -> SoftwareProduct? { - return softwareMap.product(for: bundleId) + softwareMap.product(for: bundleId) } /// Uninstalls an app. @@ -66,6 +66,6 @@ public class MasAppLibrary: AppLibrary { /// /// - Returns: true if the current user is root; false otherwise private func userIsRoot() -> Bool { - return NSUserName() == "root" + NSUserName() == "root" } } diff --git a/MasKit/Controllers/StoreSearch.swift b/MasKit/Controllers/StoreSearch.swift index cb1a737..9651370 100644 --- a/MasKit/Controllers/StoreSearch.swift +++ b/MasKit/Controllers/StoreSearch.swift @@ -48,6 +48,6 @@ extension StoreSearch { /// - Parameter appId: MAS app identifier. /// - Returns: String URL for the lookup service. func lookupURLString(forApp appId: Int) -> String? { - return "https://itunes.apple.com/lookup?id=\(appId)" + "https://itunes.apple.com/lookup?id=\(appId)" } } diff --git a/MasKit/Extensions/Dictionary+StringOrEmpty.swift b/MasKit/Extensions/Dictionary+StringOrEmpty.swift index 1d1f614..b7b6587 100644 --- a/MasKit/Extensions/Dictionary+StringOrEmpty.swift +++ b/MasKit/Extensions/Dictionary+StringOrEmpty.swift @@ -10,6 +10,6 @@ import Foundation extension Dictionary { func stringOrEmpty(key: Key) -> String { - return self[key] as? String ?? "" + self[key] as? String ?? "" } } diff --git a/MasKit/Extensions/String+PercentEncoding.swift b/MasKit/Extensions/String+PercentEncoding.swift index 51d936c..2f6ca83 100644 --- a/MasKit/Extensions/String+PercentEncoding.swift +++ b/MasKit/Extensions/String+PercentEncoding.swift @@ -8,9 +8,9 @@ import Foundation -public extension String { +extension String { /// Return an URL encoded string - var URLEncodedString: String? { - return addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) + public var URLEncodedString: String? { + addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) } } diff --git a/MasKit/ExternalCommands/ExternalCommand.swift b/MasKit/ExternalCommands/ExternalCommand.swift index bf606c0..04eec21 100644 --- a/MasKit/ExternalCommands/ExternalCommand.swift +++ b/MasKit/ExternalCommands/ExternalCommand.swift @@ -38,15 +38,15 @@ extension ExternalCommand { } public var exitCode: Int? { - return Int(process.terminationStatus) + Int(process.terminationStatus) } public var succeeded: Bool { - return exitCode == 0 + exitCode == 0 } public var failed: Bool { - return !succeeded + !succeeded } /// Runs the command. diff --git a/MasKit/Formatters/AppListFormatter.swift b/MasKit/Formatters/AppListFormatter.swift index 3f8d5a8..b1e06ce 100644 --- a/MasKit/Formatters/AppListFormatter.swift +++ b/MasKit/Formatters/AppListFormatter.swift @@ -10,7 +10,6 @@ import Foundation /// Formats text output for the search command. struct AppListFormatter { - static let idColumnMinWidth = 10 static let nameColumnMinWidth = 50 @@ -21,7 +20,7 @@ struct AppListFormatter { static func format(products: [SoftwareProduct]) -> String { // find longest appName for formatting, default 50 let maxLength = - products.map { $0.appNameOrBbundleIdentifier } + products.map(\.appNameOrBbundleIdentifier) .max(by: { $1.count > $0.count })? .count ?? nameColumnMinWidth diff --git a/MasKit/Formatters/SearchResultFormatter.swift b/MasKit/Formatters/SearchResultFormatter.swift index 5a2ff28..3d0c7d2 100644 --- a/MasKit/Formatters/SearchResultFormatter.swift +++ b/MasKit/Formatters/SearchResultFormatter.swift @@ -17,7 +17,7 @@ struct SearchResultFormatter { static func format(results: [SearchResult], includePrice: Bool = false) -> String { // find longest appName for formatting, default 50 let maxLength = - results.map { $0.trackName }.max(by: { $1.count > $0.count })?.count + results.map(\.trackName).max(by: { $1.count > $0.count })?.count ?? 50 var output: String = "" diff --git a/MasKit/Models/SoftwareProduct.swift b/MasKit/Models/SoftwareProduct.swift index 5f3a156..230697b 100644 --- a/MasKit/Models/SoftwareProduct.swift +++ b/MasKit/Models/SoftwareProduct.swift @@ -18,7 +18,7 @@ public protocol SoftwareProduct { // MARK: - Equatable extension SoftwareProduct { static func == (lhs: Self, rhs: Self) -> Bool { - return lhs.appName == rhs.appName + lhs.appName == rhs.appName && lhs.bundleIdentifier == rhs.bundleIdentifier && lhs.bundlePath == rhs.bundlePath && lhs.bundleVersion == rhs.bundleVersion diff --git a/MasKitTests/Controllers/AppLibraryMock.swift b/MasKitTests/Controllers/AppLibraryMock.swift index 0153b13..61d70c4 100644 --- a/MasKitTests/Controllers/AppLibraryMock.swift +++ b/MasKitTests/Controllers/AppLibraryMock.swift @@ -16,7 +16,7 @@ class AppLibraryMock: AppLibrary { /// - Parameter bundleId: Bundle identifier of app. /// - Returns: Software Product of app if found; nil otherwise. public func installedApp(forBundleId _: String) -> SoftwareProduct? { - return nil + nil } func uninstallApp(app: SoftwareProduct) throws { diff --git a/MasKitTests/Controllers/MasAppLibrarySpec.swift b/MasKitTests/Controllers/MasAppLibrarySpec.swift index 3425705..50921f8 100644 --- a/MasKitTests/Controllers/MasAppLibrarySpec.swift +++ b/MasKitTests/Controllers/MasAppLibrarySpec.swift @@ -34,7 +34,8 @@ let myApp = SoftwareProductMock( bundleIdentifier: "com.example", bundlePath: "", bundleVersion: "", - itemIdentifier: 1234) + itemIdentifier: 1234 +) var apps: [SoftwareProduct] = [myApp] @@ -43,7 +44,7 @@ struct SoftwareMapMock: SoftwareMap { var products: [SoftwareProduct] = [] func allSoftwareProducts() -> [SoftwareProduct] { - return products + products } func product(for bundleIdentifier: String) -> SoftwareProduct? { diff --git a/MasKitTests/Controllers/StoreSearchSpec.swift b/MasKitTests/Controllers/StoreSearchSpec.swift index caf3738..87b219e 100644 --- a/MasKitTests/Controllers/StoreSearchSpec.swift +++ b/MasKitTests/Controllers/StoreSearchSpec.swift @@ -12,8 +12,8 @@ import Quick /// Protocol minimal implementation struct StoreSearchForTesting: StoreSearch { - func lookup(app _: Int) throws -> SearchResult? { return nil } - func search(for _: String) throws -> SearchResultList { return SearchResultList(resultCount: 0, results: []) } + func lookup(app _: Int) throws -> SearchResult? { nil } + func search(for _: String) throws -> SearchResultList { SearchResultList(resultCount: 0, results: []) } } class StoreSearchSpec: QuickSpec { diff --git a/MasKitTests/Errors/MASErrorTestCase.swift b/MasKitTests/Errors/MASErrorTestCase.swift index 98d8ee9..4130f7a 100644 --- a/MasKitTests/Errors/MASErrorTestCase.swift +++ b/MasKitTests/Errors/MASErrorTestCase.swift @@ -20,7 +20,7 @@ class MASErrorTestCase: XCTestCase { /// value of the next NSError created. Only used when the NSError does not have a user info /// entry for localized description. var localizedDescription: String { - get { return "dummy value" } + get { "dummy value" } set { NSError.setUserInfoValueProvider(forDomain: errorDomain) { (_: Error, _: String) -> Any? in newValue diff --git a/MasKitTests/Extensions/Bundle+JSON.swift b/MasKitTests/Extensions/Bundle+JSON.swift index 0c3951d..b05bb55 100644 --- a/MasKitTests/Extensions/Bundle+JSON.swift +++ b/MasKitTests/Extensions/Bundle+JSON.swift @@ -24,7 +24,7 @@ extension Bundle { /// - Parameter fileName: Name of file to locate. /// - Returns: URL to file. static func url(for fileName: String) -> URL? { - return Bundle(for: NetworkSessionMock.self).url(for: fileName) + Bundle(for: NetworkSessionMock.self).url(for: fileName) } /// Builds a URL for a file in the JSON directory of the current bundle. @@ -36,7 +36,8 @@ extension Bundle { let path = self.path( forResource: fileName.fileNameWithoutExtension, ofType: fileName.fileExtension, - inDirectory: "JSON") + inDirectory: "JSON" + ) else { fatalError("Unable to load file \(fileName)") } return URL(fileURLWithPath: path) diff --git a/MasKitTests/Extensions/String+FileExtension.swift b/MasKitTests/Extensions/String+FileExtension.swift index 8fa2cff..1c08969 100644 --- a/MasKitTests/Extensions/String+FileExtension.swift +++ b/MasKitTests/Extensions/String+FileExtension.swift @@ -11,11 +11,11 @@ import Foundation extension String { /// Returns the file name before the extension. var fileNameWithoutExtension: String { - return (self as NSString).deletingPathExtension + (self as NSString).deletingPathExtension } /// Returns the file extension. var fileExtension: String { - return (self as NSString).pathExtension + (self as NSString).pathExtension } } diff --git a/MasKitTests/ExternalCommands/OpenSystemCommandSpec.swift b/MasKitTests/ExternalCommands/OpenSystemCommandSpec.swift index 42d6a88..c8a24dc 100644 --- a/MasKitTests/ExternalCommands/OpenSystemCommandSpec.swift +++ b/MasKitTests/ExternalCommands/OpenSystemCommandSpec.swift @@ -14,7 +14,6 @@ import Quick class OpenSystemCommandSpec: QuickSpec { override func spec() { describe("open system command") { - context("binary path") { it("defaults to the macOS open command") { let cmd = OpenSystemCommand() diff --git a/MasKitTests/Network/TestURLSessionDelegate.swift b/MasKitTests/Network/TestURLSessionDelegate.swift index 2ed475e..872d820 100644 --- a/MasKitTests/Network/TestURLSessionDelegate.swift +++ b/MasKitTests/Network/TestURLSessionDelegate.swift @@ -31,7 +31,7 @@ class TestURLSessionDelegate: NSObject, URLSessionDelegate { } } - struct Constants { + enum Constants { // A list of hosts you allow self-signed certificates on. // You'd likely have your dev/test servers here. // Please don't put your production server here! diff --git a/MasKitTests/Nimble/ResultPredicates.swift b/MasKitTests/Nimble/ResultPredicates.swift index 55a89e5..c6c343c 100644 --- a/MasKitTests/Nimble/ResultPredicates.swift +++ b/MasKitTests/Nimble/ResultPredicates.swift @@ -11,8 +11,8 @@ import Nimble @testable import MasKit /// Nimble predicate for result enum success case, no associated value -func beSuccess() -> Predicate> { - return Predicate.define("be ") { expression, message in +func beSuccess() -> Predicate> { + Predicate.define("be ") { expression, message in if case .success = try expression.evaluate() { return PredicateResult(status: .matches, message: message) } @@ -21,8 +21,8 @@ func beSuccess() -> Predicate> { } /// Nimble predicate for result enum failure with associated error -func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate> { - return Predicate.define("be ") { expression, message in +func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate> { + Predicate.define("be ") { expression, message in if case let .failure(error) = try expression.evaluate() { test(error) return PredicateResult(status: .matches, message: message) diff --git a/MasKitTests/OutputListener.swift b/MasKitTests/OutputListener.swift index f639f62..7f4b8c8 100644 --- a/MasKitTests/OutputListener.swift +++ b/MasKitTests/OutputListener.swift @@ -75,11 +75,11 @@ extension OutputListener { extension OutputListener { /// File descriptor for stdout (aka STDOUT_FILENO) var stdoutFileDescriptor: Int32 { - return FileHandle.standardOutput.fileDescriptor + FileHandle.standardOutput.fileDescriptor } /// File descriptor for stderr (aka STDERR_FILENO) var stderrFileDescriptor: Int32 { - return FileHandle.standardError.fileDescriptor + FileHandle.standardError.fileDescriptor } } diff --git a/MasKitTests/Strongify.swift b/MasKitTests/Strongify.swift index f384047..3e58d8f 100644 --- a/MasKitTests/Strongify.swift +++ b/MasKitTests/Strongify.swift @@ -12,10 +12,12 @@ func strongify( _ context: Context?, closure: @escaping (Context, Arguments) -> Void ) -> (Arguments) -> Void { - return { [weak context] arguments in + let strongified = { [weak context] (arguments: Arguments) in guard let strongContext = context else { return } closure(strongContext, arguments) } + + return strongified } func strongify(_ context: Context?, closure: @escaping (Context) -> Void) { diff --git a/script/lint b/script/lint index a2b1471..7fba06e 100755 --- a/script/lint +++ b/script/lint @@ -13,6 +13,7 @@ git diff --check echo echo "--> 🕊️ Swift" +swiftformat . for SOURCE in mas MasKit MasKitTests; do swift-format format --in-place --configuration .swift-format --recursive ${SOURCE} done