From 14f072367503c2304f0f1c8a93a468676f989411 Mon Sep 17 00:00:00 2001 From: Maxime Marinel Date: Wed, 30 Aug 2023 11:36:30 +0200 Subject: [PATCH] Swiftformat --- .swift-version | 2 +- App/Features/Entry/EntryView.swift | 13 ++++++------- App/Features/Entry/UI/ArchiveEntryButton.swift | 2 +- App/Features/Entry/UI/DeleteEntryButton.swift | 2 +- App/Features/Entry/UI/FontSizeSelectorView.swift | 2 +- App/Features/Entry/UI/StarEntryButton.swift | 2 +- App/Features/MainView.swift | 2 +- App/Features/PasteBoard/PasteBoardView.swift | 4 ++-- .../ClientIdClientSecretViewModel.swift | 4 ++-- App/Features/Registration/Login/LoginView.swift | 2 +- .../Registration/Login/LoginViewModel.swift | 6 +++--- .../Registration/Server/ServerViewModel.swift | 4 ++-- App/Features/Search/SearchView.swift | 4 ++-- App/Features/Sync/CoreDataSync.swift | 6 ++---- App/Features/Tag/TagListFor.swift | 6 +++--- App/Features/Tag/TagRow.swift | 6 +++--- App/Features/Tag/TagsForEntryPublisher.swift | 2 +- App/Features/Tip/TipView.swift | 4 ++-- App/Lib/WallabagSession.swift | 2 +- .../Endpoint/WallabagEntryEndpoint.swift | 4 +++- .../WallabagKit/Endpoint/WallabagOAuth.swift | 2 +- bagit/ShareViewController.swift | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- 23 files changed, 43 insertions(+), 44 deletions(-) diff --git a/.swift-version b/.swift-version index 760606e1..3659ea2f 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -5.7 +5.8 diff --git a/App/Features/Entry/EntryView.swift b/App/Features/Entry/EntryView.swift index ec30e505..9a2d2b48 100644 --- a/App/Features/Entry/EntryView.swift +++ b/App/Features/Entry/EntryView.swift @@ -53,7 +53,7 @@ struct EntryView: View { title: Text("Confirm delete?"), buttons: [ .destructive(Text("Delete")) { - self.context.delete(entry) + context.delete(entry) dismiss() }, .cancel(), @@ -61,10 +61,9 @@ struct EntryView: View { ) } } - } .sheet(isPresented: $showTag) { - TagListFor(tagsForEntry: TagsForEntryPublisher(entry: self.entry)) + TagListFor(tagsForEntry: TagsForEntryPublisher(entry: entry)) .environment(\.managedObjectContext, context) } #if os(iOS) @@ -75,20 +74,20 @@ struct EntryView: View { @ViewBuilder private var bottomBarButton: some View { Button(role: .destructive, action: { - self.showDeleteConfirm = true + showDeleteConfirm = true }, label: { Label("Delete", systemImage: "trash") }) Divider() Button(action: { - openURL(self.entry.url!.url!) + openURL(entry.url!.url!) }, label: { Label("Open in Safari", systemImage: "safari") }) Button(action: { - self.showTag.toggle() + showTag.toggle() }, label: { - Label("Tag", systemImage: self.showTag ? "tag.fill" : "tag") + Label("Tag", systemImage: showTag ? "tag.fill" : "tag") }) Button(action: { appSync.refresh(entry: entry) diff --git a/App/Features/Entry/UI/ArchiveEntryButton.swift b/App/Features/Entry/UI/ArchiveEntryButton.swift index 008214fd..48dcbeba 100644 --- a/App/Features/Entry/UI/ArchiveEntryButton.swift +++ b/App/Features/Entry/UI/ArchiveEntryButton.swift @@ -5,7 +5,7 @@ struct ArchiveEntryButton: View { var showText: Bool = true var body: some View { Button(action: { - self.entry.toggleArchive() + entry.toggleArchive() }, label: { if showText { Label( diff --git a/App/Features/Entry/UI/DeleteEntryButton.swift b/App/Features/Entry/UI/DeleteEntryButton.swift index 699c84c0..b0343571 100644 --- a/App/Features/Entry/UI/DeleteEntryButton.swift +++ b/App/Features/Entry/UI/DeleteEntryButton.swift @@ -6,7 +6,7 @@ struct DeleteEntryButton: View { var showText: Bool = true var body: some View { Button(action: { - self.showConfirm = true + showConfirm = true }, label: { if showText { Text("Delete") diff --git a/App/Features/Entry/UI/FontSizeSelectorView.swift b/App/Features/Entry/UI/FontSizeSelectorView.swift index 999b5082..94ae1fd5 100644 --- a/App/Features/Entry/UI/FontSizeSelectorView.swift +++ b/App/Features/Entry/UI/FontSizeSelectorView.swift @@ -9,7 +9,7 @@ struct FontSizeSelectorView: View { HStack { Button(action: { withAnimation { - self.showSelector = !self.showSelector + showSelector = !showSelector } }, label: { Image(systemName: "textformat.size") diff --git a/App/Features/Entry/UI/StarEntryButton.swift b/App/Features/Entry/UI/StarEntryButton.swift index aa9b3224..9893d636 100644 --- a/App/Features/Entry/UI/StarEntryButton.swift +++ b/App/Features/Entry/UI/StarEntryButton.swift @@ -5,7 +5,7 @@ struct StarEntryButton: View { var showText: Bool = true var body: some View { Button(action: { - self.entry.toggleStarred() + entry.toggleStarred() }, label: { if showText { Label( diff --git a/App/Features/MainView.swift b/App/Features/MainView.swift index 590876da..578eac05 100644 --- a/App/Features/MainView.swift +++ b/App/Features/MainView.swift @@ -46,7 +46,7 @@ struct MainView: View { }) Divider() Button(role: .destructive, action: { - self.appState.logout() + appState.logout() }, label: { Label("Logout", systemImage: "person") }).foregroundColor(.red) diff --git a/App/Features/PasteBoard/PasteBoardView.swift b/App/Features/PasteBoard/PasteBoardView.swift index eaaaae75..49d98c67 100644 --- a/App/Features/PasteBoard/PasteBoardView.swift +++ b/App/Features/PasteBoard/PasteBoardView.swift @@ -15,12 +15,12 @@ import SwiftUI .lineLimit(1) HStack { Button(action: { - self.pasteBoardViewModel.addUrl() + pasteBoardViewModel.addUrl() }, label: { Text("Add") }) Button(action: { - self.pasteBoardViewModel.hide() + pasteBoardViewModel.hide() }, label: { Text("Cancel") }) diff --git a/App/Features/Registration/ClientIdClientSecret/ClientIdClientSecretViewModel.swift b/App/Features/Registration/ClientIdClientSecret/ClientIdClientSecretViewModel.swift index d4e9407d..b01d968b 100644 --- a/App/Features/Registration/ClientIdClientSecret/ClientIdClientSecretViewModel.swift +++ b/App/Features/Registration/ClientIdClientSecret/ClientIdClientSecretViewModel.swift @@ -16,8 +16,8 @@ class ClientIdSecretViewModel: ObservableObject { clientSecret = WallabagUserDefaults.clientSecret cancellable = Publishers.CombineLatest($clientId, $clientSecret).sink { [unowned self] clientId, clientSecret in - self.isValid = !clientId.isEmpty && !clientSecret.isEmpty - if self.isValid { + isValid = !clientId.isEmpty && !clientSecret.isEmpty + if isValid { WallabagUserDefaults.clientId = clientId.trimmingCharacters(in: .whitespacesAndNewlines) WallabagUserDefaults.clientSecret = clientSecret.trimmingCharacters(in: .whitespacesAndNewlines) } diff --git a/App/Features/Registration/Login/LoginView.swift b/App/Features/Registration/Login/LoginView.swift index 70e9ee4d..13fd1abd 100644 --- a/App/Features/Registration/Login/LoginView.swift +++ b/App/Features/Registration/Login/LoginView.swift @@ -16,7 +16,7 @@ struct LoginView: View { SecureField("Password", text: $loginViewModel.password) } Button("Login") { - self.loginViewModel.tryLogin() + loginViewModel.tryLogin() }.disabled(!loginViewModel.isValid) loginViewModel.error.map { error in VStack { diff --git a/App/Features/Registration/Login/LoginViewModel.swift b/App/Features/Registration/Login/LoginViewModel.swift index 4bc659a9..4af5837f 100644 --- a/App/Features/Registration/Login/LoginViewModel.swift +++ b/App/Features/Registration/Login/LoginViewModel.swift @@ -18,15 +18,15 @@ class LoginViewModel: ObservableObject { init() { login = WallabagUserDefaults.login Publishers.CombineLatest($login, $password).sink { [unowned self] login, password in - self.isValid = !login.isEmpty && !password.isEmpty + isValid = !login.isEmpty && !password.isEmpty }.store(in: &cancellable) session.$state.receive(on: DispatchQueue.main).sink { [unowned self] state in switch state { case let .error(reason): - self.error = reason + error = reason case .connected: - self.appState.registred = true + appState.registred = true case .unknown, .connecting, .offline: break } diff --git a/App/Features/Registration/Server/ServerViewModel.swift b/App/Features/Registration/Server/ServerViewModel.swift index bdf7468a..b0ae09c1 100644 --- a/App/Features/Registration/Server/ServerViewModel.swift +++ b/App/Features/Registration/Server/ServerViewModel.swift @@ -12,8 +12,8 @@ final class ServerViewModel: ObservableObject { init() { url = WallabagUserDefaults.host cancellable = $url.sink { [unowned self] url in - self.isValid = self.validateServer(host: url) - if self.isValid { + isValid = validateServer(host: url) + if isValid { WallabagUserDefaults.host = url } } diff --git a/App/Features/Search/SearchView.swift b/App/Features/Search/SearchView.swift index 3385a8d7..bd1ccb05 100644 --- a/App/Features/Search/SearchView.swift +++ b/App/Features/Search/SearchView.swift @@ -28,10 +28,10 @@ struct SearchView: View { } Button(action: { withAnimation { - self.showSearchBar = !self.showSearchBar + showSearchBar = !showSearchBar } }, label: { - Image(systemName: self.showSearchBar ? "list.bullet.below.rectangle" : "magnifyingglass") + Image(systemName: showSearchBar ? "list.bullet.below.rectangle" : "magnifyingglass") .padding(.trailing) }) .buttonStyle(.plain) diff --git a/App/Features/Sync/CoreDataSync.swift b/App/Features/Sync/CoreDataSync.swift index 6a1a70d1..4061d4e4 100644 --- a/App/Features/Sync/CoreDataSync.swift +++ b/App/Features/Sync/CoreDataSync.swift @@ -27,11 +27,9 @@ class CoreDataSync { } } - // swiftlint:disable force_cast private func deletedObjects(_ deletedObjects: Set) { deletedObjects - .filter { $0 is Entry } - .map { entry -> Entry in entry as! Entry } + .compactMap { $0 as? Entry } .forEach { entry in self.wallabagSession.delete(entry: entry) } @@ -48,7 +46,7 @@ class CoreDataSync { changedValues.removeValue(forKey: "tags") if changedValues.count > 0 { logger.debug("Push update entry \(entry.id) to remote") - self.wallabagSession.update( + wallabagSession.update( entry, parameters: [ diff --git a/App/Features/Tag/TagListFor.swift b/App/Features/Tag/TagListFor.swift index f868801f..bb711bf3 100644 --- a/App/Features/Tag/TagListFor.swift +++ b/App/Features/Tag/TagListFor.swift @@ -13,12 +13,12 @@ struct TagListFor: View { HStack { TextField("New tag", text: $tagLabel) Button(action: { - self.tagsForEntry.add(tag: self.tagLabel) - self.tagLabel = "" + tagsForEntry.add(tag: tagLabel) + tagLabel = "" }, label: { Text("Add") }) }.padding(.horizontal) List(tagsForEntry.tags) { tag in - TagRow(tag: tag, tagsForEntry: self.tagsForEntry) + TagRow(tag: tag, tagsForEntry: tagsForEntry) } } } diff --git a/App/Features/Tag/TagRow.swift b/App/Features/Tag/TagRow.swift index e6a9aa5b..0596393f 100644 --- a/App/Features/Tag/TagRow.swift +++ b/App/Features/Tag/TagRow.swift @@ -12,10 +12,10 @@ struct TagRow: View { Image(systemName: "checkmark") } }.onTapGesture { - if self.tag.isChecked { - self.tagsForEntry.delete(tag: self.tag) + if tag.isChecked { + tagsForEntry.delete(tag: tag) } else { - self.tagsForEntry.add(tag: self.tag) + tagsForEntry.add(tag: tag) } } } diff --git a/App/Features/Tag/TagsForEntryPublisher.swift b/App/Features/Tag/TagsForEntryPublisher.swift index a2bffa2a..513a7b0f 100644 --- a/App/Features/Tag/TagsForEntryPublisher.swift +++ b/App/Features/Tag/TagsForEntryPublisher.swift @@ -3,7 +3,7 @@ import CoreData import Factory import Foundation -// swiftlint:disable all +// swiftlint:disable:next all class TagsForEntryPublisher: ObservableObject { @Injected(\.wallabagSession) private var session diff --git a/App/Features/Tip/TipView.swift b/App/Features/Tip/TipView.swift index 903c9bef..e27d9324 100644 --- a/App/Features/Tip/TipView.swift +++ b/App/Features/Tip/TipView.swift @@ -21,11 +21,11 @@ struct TipView: View { HStack { Spacer() if tipViewModel.canMakePayments { - if self.tipViewModel.tipProduct != nil { + if tipViewModel.tipProduct != nil { Button( action: { Task { await purchase() } }, label: { - self.tipViewModel.tipProduct.map { product in + tipViewModel.tipProduct.map { product in HStack { Text(product.displayName) Text(product.displayPrice) diff --git a/App/Lib/WallabagSession.swift b/App/Lib/WallabagSession.swift index e7bedf01..ff296875 100644 --- a/App/Lib/WallabagSession.swift +++ b/App/Lib/WallabagSession.swift @@ -53,7 +53,7 @@ class WallabagSession: ObservableObject { kit.send(to: WallabagEntryEndpoint.add(url: url)) .catch { _ in Empty() } .sink { [unowned self] (wallabagEntry: WallabagEntry) in - let entry = Entry(context: self.coreDataContext) + let entry = Entry(context: coreDataContext) entry.hydrate(from: wallabagEntry) completion() } diff --git a/WallabagKit/Sources/WallabagKit/Endpoint/WallabagEntryEndpoint.swift b/WallabagKit/Sources/WallabagKit/Endpoint/WallabagEntryEndpoint.swift index 54a46ab5..9d95d0bb 100644 --- a/WallabagKit/Sources/WallabagKit/Endpoint/WallabagEntryEndpoint.swift +++ b/WallabagKit/Sources/WallabagKit/Endpoint/WallabagEntryEndpoint.swift @@ -50,14 +50,16 @@ public enum WallabagEntryEndpoint: WallabagKitEndpoint { } } - // swiftlint:disable force_try public func getBody() -> Data { switch self { case let .add(url): + // swiftlint:disable:next force_try return try! JSONSerialization.data(withJSONObject: ["url": url], options: .prettyPrinted) case let .update(_, parameters): + // swiftlint:disable:next force_try return try! JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) case let .addTag(tag, _): + // swiftlint:disable:next force_try return try! JSONSerialization.data(withJSONObject: ["tags": tag], options: .prettyPrinted) default: return "".data(using: .utf8)! diff --git a/WallabagKit/Sources/WallabagKit/Endpoint/WallabagOAuth.swift b/WallabagKit/Sources/WallabagKit/Endpoint/WallabagOAuth.swift index 549c1485..05fd6948 100644 --- a/WallabagKit/Sources/WallabagKit/Endpoint/WallabagOAuth.swift +++ b/WallabagKit/Sources/WallabagKit/Endpoint/WallabagOAuth.swift @@ -12,10 +12,10 @@ enum WallabagOauth: WallabagKitEndpoint { } } - // swiftlint:disable force_try func getBody() -> Data { switch self { case let .request(clientId, clientSecret, username, password): + // swiftlint:disable:next force_try return try! JSONSerialization.data(withJSONObject: [ "grant_type": "password", "client_id": clientId, diff --git a/bagit/ShareViewController.swift b/bagit/ShareViewController.swift index bf1e84f2..17e113a8 100644 --- a/bagit/ShareViewController.swift +++ b/bagit/ShareViewController.swift @@ -38,7 +38,7 @@ class ShareViewController: UIViewController { view.addSubview(backView) view.addSubview(notificationView) UIView.animate(withDuration: 0.3) { [unowned self] in - self.backView.alpha = 0.6 + backView.alpha = 0.6 } } diff --git a/wallabag.xcworkspace/xcshareddata/swiftpm/Package.resolved b/wallabag.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0340b463..d2a17eee 100644 --- a/wallabag.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/wallabag.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:hmlongco/Factory.git", "state" : { - "revision" : "718466174b5e8eb0dc6548260f447d2b5b639111", - "version" : "2.0.0" + "revision" : "061b3afe0358a0da7ce568f8272c847910be3dd7", + "version" : "2.2.0" } }, {