Chop down multiline guard clauses.

Partial #585

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2024-10-25 13:17:23 -04:00
parent 59a642590a
commit 6bf5696093
No known key found for this signature in database
6 changed files with 21 additions and 11 deletions

View file

@ -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.
guard case MASError.downloadFailed(let downloadError) = error,
guard
case MASError.downloadFailed(let downloadError) = error,
case NSURLErrorDomain = downloadError?.domain
else {
throw error

View file

@ -20,7 +20,8 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
}
func downloadQueue(_ queue: CKDownloadQueue, statusChangedFor download: SSDownload) {
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
guard
download.metadata.itemIdentifier == purchase.itemIdentifier,
let status = download.status
else {
return
@ -42,7 +43,8 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
}
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
guard
download.metadata.itemIdentifier == purchase.itemIdentifier,
let status = download.status
else {
return

View file

@ -85,7 +85,8 @@ class MasStoreSearch: StoreSearch {
self.scrapeAppStoreVersion(pageURL)
}
.map { pageVersion in
guard let pageVersion,
guard
let pageVersion,
let searchVersion = Version(tolerant: result.version),
pageVersion > searchVersion
else {
@ -125,7 +126,8 @@ class MasStoreSearch: StoreSearch {
networkManager.loadData(from: pageURL)
}
.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 version = Version(tolerant: capture)
else {

View file

@ -45,7 +45,8 @@ extension SoftwareProduct {
// The App Store does not enforce semantic versioning, but we assume most apps follow versioning
// schemes that increase numerically over time.
guard let semanticBundleVersion = Version(tolerant: bundleVersion),
guard
let semanticBundleVersion = Version(tolerant: bundleVersion),
let semanticAppStoreVersion = Version(tolerant: storeApp.version)
else {
// If a version string can't be parsed as a Semantic Version, our best effort is to check for

View file

@ -30,7 +30,8 @@ extension Bundle {
.bundleURL
.deletingLastPathComponent()
.appendingPathComponent("mas_masTests.bundle")
guard let bundle = Bundle(url: bundleURL),
guard
let bundle = Bundle(url: bundleURL),
let url = bundle.url(for: fileName)
else {
fatalError("Unable to load file \(fileName)")

View file

@ -90,11 +90,14 @@ private extension MyClass {
guard let singleTest = somethingFailable() else { return }
guard statementThatShouldBeTrue else { return }
// If there is one long expression to guard or multiple expressions
// move else to next line
guard let oneItem = somethingFailable(),
// If a guard clause requires multiple lines, chop down, then start `else` new line
// In this case, always chop down else clause.
guard
let oneItem = somethingFailable(),
let secondItem = somethingFailable2()
else { return }
else {
return
}
// If the return in else is long, move to next line
guard let something = somethingFailable() else {