mirror of
https://github.com/mas-cli/mas
synced 2024-11-21 11:13:06 +00:00
Chop down multiline guard
clauses.
Partial #585 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
parent
59a642590a
commit
6bf5696093
6 changed files with 21 additions and 11 deletions
|
@ -47,7 +47,8 @@ private func downloadWithRetries(_ appID: AppID, purchase: Bool = false, attempt
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the download failed due to network issues, try again. Otherwise, fail immediately.
|
// If the download failed due to network issues, try again. Otherwise, fail immediately.
|
||||||
guard case MASError.downloadFailed(let downloadError) = error,
|
guard
|
||||||
|
case MASError.downloadFailed(let downloadError) = error,
|
||||||
case NSURLErrorDomain = downloadError?.domain
|
case NSURLErrorDomain = downloadError?.domain
|
||||||
else {
|
else {
|
||||||
throw error
|
throw error
|
||||||
|
|
|
@ -20,7 +20,8 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadQueue(_ queue: CKDownloadQueue, statusChangedFor download: SSDownload) {
|
func downloadQueue(_ queue: CKDownloadQueue, statusChangedFor download: SSDownload) {
|
||||||
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
|
guard
|
||||||
|
download.metadata.itemIdentifier == purchase.itemIdentifier,
|
||||||
let status = download.status
|
let status = download.status
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
|
@ -42,7 +43,8 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
|
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
|
||||||
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
|
guard
|
||||||
|
download.metadata.itemIdentifier == purchase.itemIdentifier,
|
||||||
let status = download.status
|
let status = download.status
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
|
|
|
@ -85,7 +85,8 @@ class MasStoreSearch: StoreSearch {
|
||||||
self.scrapeAppStoreVersion(pageURL)
|
self.scrapeAppStoreVersion(pageURL)
|
||||||
}
|
}
|
||||||
.map { pageVersion in
|
.map { pageVersion in
|
||||||
guard let pageVersion,
|
guard
|
||||||
|
let pageVersion,
|
||||||
let searchVersion = Version(tolerant: result.version),
|
let searchVersion = Version(tolerant: result.version),
|
||||||
pageVersion > searchVersion
|
pageVersion > searchVersion
|
||||||
else {
|
else {
|
||||||
|
@ -125,7 +126,8 @@ class MasStoreSearch: StoreSearch {
|
||||||
networkManager.loadData(from: pageURL)
|
networkManager.loadData(from: pageURL)
|
||||||
}
|
}
|
||||||
.map { data in
|
.map { data in
|
||||||
guard let html = String(data: data, encoding: .utf8),
|
guard
|
||||||
|
let html = String(data: data, encoding: .utf8),
|
||||||
let capture = Self.appVersionExpression.firstMatch(in: html)?.captures[0],
|
let capture = Self.appVersionExpression.firstMatch(in: html)?.captures[0],
|
||||||
let version = Version(tolerant: capture)
|
let version = Version(tolerant: capture)
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -45,7 +45,8 @@ extension SoftwareProduct {
|
||||||
|
|
||||||
// The App Store does not enforce semantic versioning, but we assume most apps follow versioning
|
// The App Store does not enforce semantic versioning, but we assume most apps follow versioning
|
||||||
// schemes that increase numerically over time.
|
// schemes that increase numerically over time.
|
||||||
guard let semanticBundleVersion = Version(tolerant: bundleVersion),
|
guard
|
||||||
|
let semanticBundleVersion = Version(tolerant: bundleVersion),
|
||||||
let semanticAppStoreVersion = Version(tolerant: storeApp.version)
|
let semanticAppStoreVersion = Version(tolerant: storeApp.version)
|
||||||
else {
|
else {
|
||||||
// If a version string can't be parsed as a Semantic Version, our best effort is to check for
|
// If a version string can't be parsed as a Semantic Version, our best effort is to check for
|
||||||
|
|
|
@ -30,7 +30,8 @@ extension Bundle {
|
||||||
.bundleURL
|
.bundleURL
|
||||||
.deletingLastPathComponent()
|
.deletingLastPathComponent()
|
||||||
.appendingPathComponent("mas_masTests.bundle")
|
.appendingPathComponent("mas_masTests.bundle")
|
||||||
guard let bundle = Bundle(url: bundleURL),
|
guard
|
||||||
|
let bundle = Bundle(url: bundleURL),
|
||||||
let url = bundle.url(for: fileName)
|
let url = bundle.url(for: fileName)
|
||||||
else {
|
else {
|
||||||
fatalError("Unable to load file \(fileName)")
|
fatalError("Unable to load file \(fileName)")
|
||||||
|
|
|
@ -90,11 +90,14 @@ private extension MyClass {
|
||||||
guard let singleTest = somethingFailable() else { return }
|
guard let singleTest = somethingFailable() else { return }
|
||||||
guard statementThatShouldBeTrue else { return }
|
guard statementThatShouldBeTrue else { return }
|
||||||
|
|
||||||
// If there is one long expression to guard or multiple expressions
|
// If a guard clause requires multiple lines, chop down, then start `else` new line
|
||||||
// move else to next line
|
// In this case, always chop down else clause.
|
||||||
guard let oneItem = somethingFailable(),
|
guard
|
||||||
|
let oneItem = somethingFailable(),
|
||||||
let secondItem = somethingFailable2()
|
let secondItem = somethingFailable2()
|
||||||
else { return }
|
else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// If the return in else is long, move to next line
|
// If the return in else is long, move to next line
|
||||||
guard let something = somethingFailable() else {
|
guard let something = somethingFailable() else {
|
||||||
|
|
Loading…
Reference in a new issue