🧹 Lint with swiftformat

This commit is contained in:
Chris Araman 2021-03-21 22:46:17 -07:00
parent df9730d65f
commit 3bc25449b0
No known key found for this signature in database
GPG key ID: BB4499D9E11B61E0
43 changed files with 88 additions and 84 deletions

View file

@ -14,6 +14,7 @@
--enable trailingClosures
# Rule options
--commas inline
--guardelse same-line
--commas always
--extensionacl on-declarations
--importgrouping testable-last
--ranges no-space

View file

@ -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)
}
}

View file

@ -11,7 +11,7 @@ import StoreFoundation
extension ISStoreAccount: StoreAccount {
static var primaryAccountIsPresentAndSignedIn: Bool {
return CKAccountStore.shared().primaryAccountIsPresentAndSignedIn
CKAccountStore.shared().primaryAccountIsPresentAndSignedIn
}
static var primaryAccount: StoreAccount? {

View file

@ -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)
}
}

View file

@ -35,7 +35,7 @@ extension SSPurchase {
buyParameters =
parameters.map { key, value in
return "\(key)=\(value)"
"\(key)=\(value)"
}
.joined(separator: "&")

View file

@ -17,7 +17,7 @@ public struct AccountCommand: CommandProtocol {
public init() {}
/// Runs the command.
public func run(_: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<Void, MASError> {
if let account = ISStoreAccount.primaryAccount {
print(String(describing: account.identifier))
} else {

View file

@ -29,7 +29,7 @@ public struct HomeCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: HomeOptions) -> Result<(), MASError> {
public func run(_ options: HomeOptions) -> Result<Void, MASError> {
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<HomeOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "ID of app to show on MAS Preview")
}
}

View file

@ -23,7 +23,7 @@ public struct InfoCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: InfoOptions) -> Result<(), MASError> {
public func run(_ options: InfoOptions) -> Result<Void, MASError> {
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<InfoOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "ID of app to show info")
}
}

View file

@ -29,7 +29,7 @@ public struct InstallCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_ options: Options) -> Result<Void, MASError> {
// 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<InstallOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "app ID(s) to install")
<*> mode <| Switch(flag: nil, key: "force", usage: "force reinstall")
}

View file

@ -29,7 +29,7 @@ public struct ListCommand: CommandProtocol {
}
/// Runs the command.
public func run(_: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<Void, MASError> {
let products = appLibrary.installedApps
if products.isEmpty {
print("No installed apps found")

View file

@ -37,7 +37,7 @@ public struct LuckyCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_ options: Options) -> Result<Void, MASError> {
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<Void, MASError> {
// 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<LuckyOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "the app name to install")
<*> mode <| Switch(flag: nil, key: "force", usage: "force reinstall")
}

View file

@ -32,7 +32,7 @@ public struct OpenCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: OpenOptions) -> Result<(), MASError> {
public func run(_ options: OpenOptions) -> Result<Void, MASError> {
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<OpenOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(defaultValue: markerValue, usage: "the app ID")
}
}

View file

@ -32,7 +32,7 @@ public struct OutdatedCommand: CommandProtocol {
}
/// Runs the command.
public func run(_: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<Void, MASError> {
for installedApp in appLibrary.installedApps {
do {
if let storeApp = try storeSearch.lookup(app: installedApp.itemIdentifier.intValue) {

View file

@ -28,7 +28,7 @@ public struct PurchaseCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_ options: Options) -> Result<Void, MASError> {
// 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<PurchaseOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "app ID(s) to install")
}
}

View file

@ -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<Void, MASError> {
/*
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<ResetOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Switch(flag: nil, key: "debug", usage: "Enable debug mode")
}
}

View file

@ -24,7 +24,7 @@ public struct SearchCommand: CommandProtocol {
self.storeSearch = storeSearch
}
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_ options: Options) -> Result<Void, MASError> {
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<SearchOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "the app name to search")
<*> mode <| Option(key: "price", defaultValue: false, usage: "Show price of found apps")
}

View file

@ -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<Void, MASError> {
if #available(macOS 10.13, *) {
return .failure(.signInDisabled)
}
@ -58,7 +58,7 @@ public struct SignInOptions: OptionsProtocol {
}
public static func evaluate(_ mode: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
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")

View file

@ -17,7 +17,7 @@ public struct SignOutCommand: CommandProtocol {
public init() {}
/// Runs the command.
public func run(_: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<Void, MASError> {
if #available(macOS 10.13, *) {
let accountService: ISAccountService = ISServiceProxy.genericShared().accountService
accountService.signOut()

View file

@ -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<Void, MASError> {
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<UninstallOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "ID of app to uninstall")
<*> mode <| Switch(flag: nil, key: "dry-run", usage: "dry run")
}

View file

@ -31,7 +31,7 @@ public struct UpgradeCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_ options: Options) -> Result<Void, MASError> {
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<UpgradeOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(defaultValue: [], usage: "app(s) to upgrade")
}
}

View file

@ -29,7 +29,7 @@ public struct VendorCommand: CommandProtocol {
}
/// Runs the command.
public func run(_ options: VendorOptions) -> Result<(), MASError> {
public func run(_ options: VendorOptions) -> Result<Void, MASError> {
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<VendorOptions, CommandantError<MASError>> {
return create
create
<*> mode <| Argument(usage: "the app ID to show the vendor's website")
}
}

View file

@ -17,7 +17,7 @@ public struct VersionCommand: CommandProtocol {
public init() {}
/// Runs the command.
public func run(_: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<Void, MASError> {
let plist = Bundle.main.infoDictionary
if let versionString = plist?["CFBundleShortVersionString"] {
print(versionString)

View file

@ -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 }
}
}

View file

@ -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"
}
}

View file

@ -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)"
}
}

View file

@ -10,6 +10,6 @@ import Foundation
extension Dictionary {
func stringOrEmpty(key: Key) -> String {
return self[key] as? String ?? ""
self[key] as? String ?? ""
}
}

View file

@ -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)
}
}

View file

@ -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.

View file

@ -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

View file

@ -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 = ""

View file

@ -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

View file

@ -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 {

View file

@ -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? {

View file

@ -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 {

View file

@ -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

View file

@ -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)

View file

@ -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
}
}

View file

@ -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()

View file

@ -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!

View file

@ -11,8 +11,8 @@ import Nimble
@testable import MasKit
/// Nimble predicate for result enum success case, no associated value
func beSuccess() -> Predicate<Result<(), MASError>> {
return Predicate.define("be <success>") { expression, message in
func beSuccess() -> Predicate<Result<Void, MASError>> {
Predicate.define("be <success>") { expression, message in
if case .success = try expression.evaluate() {
return PredicateResult(status: .matches, message: message)
}
@ -21,8 +21,8 @@ func beSuccess() -> Predicate<Result<(), MASError>> {
}
/// Nimble predicate for result enum failure with associated error
func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<(), MASError>> {
return Predicate.define("be <failure>") { expression, message in
func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<Void, MASError>> {
Predicate.define("be <failure>") { expression, message in
if case let .failure(error) = try expression.evaluate() {
test(error)
return PredicateResult(status: .matches, message: message)

View file

@ -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
}
}

View file

@ -12,10 +12,12 @@ func strongify<Context: AnyObject, Arguments>(
_ 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: AnyObject>(_ context: Context?, closure: @escaping (Context) -> Void) {

View file

@ -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