reformat some multi-line expressions

Honestly, some of this formatting seems a little weird, but it appears to thread the needle between the competing requirements of swiftformat's wrapMultilineStatementBraces rule and SwiftLint's opening_brace rule.
This commit is contained in:
Sixten Otto 2023-02-20 11:32:32 -07:00
parent 92fe2c5e33
commit f7168ff65a
11 changed files with 72 additions and 60 deletions

View file

@ -164,9 +164,10 @@ public class ShareExtensionViewModel: ObservableObject {
updateStatusOnMain(requestId: newRequestID, newStatus: .synced)
// Prefetch the newly saved content
if let itemID = newRequestID,
let currentViewer = services.dataService.currentViewer?.username,
(try? await services.dataService.loadArticleContentWithRetries(itemID: itemID, username: currentViewer)) != nil
if
let itemID = newRequestID,
let currentViewer = services.dataService.currentViewer?.username,
(try? await services.dataService.loadArticleContentWithRetries(itemID: itemID, username: currentViewer)) != nil
{
updateStatusOnMain(requestId: requestId, newStatus: .synced, objectID: linkedItemObjectID)
}

View file

@ -128,9 +128,10 @@ import Views
}
// If possible start prefetching new pages in the background
if let itemIDs = syncResult?.updatedItemIDs,
let username = dataService.currentViewer?.username,
itemIDs.count > 0
if
let itemIDs = syncResult?.updatedItemIDs,
let username = dataService.currentViewer?.username,
!itemIDs.isEmpty
{
Task.detached(priority: .background) {
await dataService.prefetchPages(itemIDs: itemIDs, username: username)

View file

@ -17,10 +17,11 @@ struct LabelsMasonaryView: View {
@State private var totalHeight = CGFloat.zero
private var labelItems: [(label: LinkedItemLabel, selected: Bool)]
init(labels allLabels: [LinkedItemLabel],
selectedLabels: [LinkedItemLabel],
onLabelTap: @escaping (LinkedItemLabel, TextChip) -> Void)
{
init(
labels allLabels: [LinkedItemLabel],
selectedLabels: [LinkedItemLabel],
onLabelTap: @escaping (LinkedItemLabel, TextChip) -> Void
) {
self.onLabelTap = onLabelTap
let selected = selectedLabels.map { (label: $0, selected: true) }

View file

@ -554,10 +554,11 @@ struct WebReaderContainerView: View {
func scrollToTop() {}
func openOriginalURL(urlString: String?) {
if let urlString = urlString,
let url = URL(string: urlString)
{
openURL(url)
}
guard
let urlString = urlString,
let url = URL(string: urlString)
else { return }
openURL(url)
}
}

View file

@ -192,10 +192,11 @@ struct SafariWebLink: Identifiable {
}
}
func setLabelsForHighlight(highlightID: String,
labelIDs: [String],
dataService: DataService)
{
func setLabelsForHighlight(
highlightID: String,
labelIDs: [String],
dataService: DataService
) {
dataService.setLabelsForHighlight(highlightID: highlightID, labelIDs: labelIDs)
}

View file

@ -13,9 +13,10 @@ public struct HighlightData {
public let highlightText: String
public static func make(dict: NSDictionary?) -> HighlightData? {
if let dict = dict,
let highlightHTML = dict["highlightHTML"] as? String,
let highlightText = dict["highlightText"] as? String
if
let dict = dict,
let highlightHTML = dict["highlightHTML"] as? String,
let highlightText = dict["highlightText"] as? String
{
return HighlightData(highlightHTML: highlightHTML, highlightText: highlightText)
}

View file

@ -84,9 +84,10 @@ class SpeechPlayerItem: AVPlayerItem {
var pendingRequests = Set<AVAssetResourceLoadingRequest>()
weak var owner: SpeechPlayerItem?
func resourceLoader(_: AVAssetResourceLoader,
shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool
{
func resourceLoader(
_: AVAssetResourceLoader,
shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest
) -> Bool {
if owner == nil {
return true
}

View file

@ -195,10 +195,11 @@ struct SpeechSynthesizer {
}
}
static func download(speechItem: SpeechItem,
redownloadCached: Bool = false,
session: URLSession = URLSession.shared) async throws -> SynthesizeData?
{
static func download(
speechItem: SpeechItem,
redownloadCached: Bool = false,
session: URLSession = URLSession.shared
) async throws -> SynthesizeData? {
let decoder = JSONDecoder()
if !redownloadCached {

View file

@ -22,10 +22,11 @@ public struct InternalRecommendation {
public static func make(_ recommendations: NSSet?) -> [InternalRecommendation] {
recommendations?
.compactMap { recommendation in
if let recommendation = recommendation as? Recommendation,
let groupID = recommendation.groupID,
let name = recommendation.name,
let recommendedAt = recommendation.recommendedAt
if
let recommendation = recommendation as? Recommendation,
let groupID = recommendation.groupID,
let name = recommendation.name,
let recommendedAt = recommendation.recommendedAt
{
return InternalRecommendation(
groupID: groupID,

View file

@ -36,9 +36,10 @@ public struct InternalRecommendationGroup: Identifiable {
}
public static func make(from recommendationGroup: RecommendationGroup) -> InternalRecommendationGroup? {
if let id = recommendationGroup.id,
let name = recommendationGroup.name,
let inviteUrl = recommendationGroup.inviteUrl
if
let id = recommendationGroup.id,
let name = recommendationGroup.name,
let inviteUrl = recommendationGroup.inviteUrl
{
return InternalRecommendationGroup(
id: id,

View file

@ -43,37 +43,39 @@ public struct InternalUserProfile: Identifiable, Encodable {
}
public static func makeSingle(_ user: UserProfile?) -> InternalUserProfile? {
if let user = user,
let userID = user.userID,
let name = user.name,
let username = user.username
{
return InternalUserProfile(
userID: userID,
name: name,
username: username,
profileImageURL: user.profileImageURL
)
guard
let user = user,
let userID = user.userID,
let name = user.name,
let username = user.username
else {
return nil
}
return nil
return InternalUserProfile(
userID: userID,
name: name,
username: username,
profileImageURL: user.profileImageURL
)
}
public static func make(_ users: NSSet?) -> [InternalUserProfile] {
users?
.compactMap { user in
if let user = user as? UserProfile,
let userID = user.userID,
let name = user.name,
let username = user.username
{
return InternalUserProfile(
userID: userID,
name: name,
username: username,
profileImageURL: user.profileImageURL
)
guard
let user = user as? UserProfile,
let userID = user.userID,
let name = user.name,
let username = user.username
else {
return nil
}
return nil
return InternalUserProfile(
userID: userID,
name: name,
username: username,
profileImageURL: user.profileImageURL
)
} ?? []
}
}