From 7c9a6bc25b089a95e8fb46e5751d6849b709f0cb Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Thu, 22 Jun 2023 11:21:09 +0300 Subject: [PATCH] Fix bugs introduced when applied "contains_over_first_not_nil" lint rule (#704) --- Zotero/Models/API/ItemResponse.swift | 4 ++-- .../Detail/Lookup/Views/ManualLookupViewController.swift | 2 +- .../Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift | 4 ++-- Zotero/Scenes/General/ViewModels/TagPickerActionHandler.swift | 2 +- .../Views/ExpandableCollectionsCollectionViewHandler.swift | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Zotero/Models/API/ItemResponse.swift b/Zotero/Models/API/ItemResponse.swift index 3ca231dca..a4518e666 100644 --- a/Zotero/Models/API/ItemResponse.swift +++ b/Zotero/Models/API/ItemResponse.swift @@ -315,14 +315,14 @@ struct ItemResponse { } case FieldKeys.Item.Annotation.Position.paths: - guard let parsedPaths = object.value as? [[Double]], !parsedPaths.isEmpty && parsedPaths.contains(where: { $0.count % 2 != 0 }) else { + guard let parsedPaths = object.value as? [[Double]], !parsedPaths.isEmpty && !parsedPaths.contains(where: { $0.count % 2 != 0 }) else { throw SchemaError.invalidValue(value: "\(object.value)", field: FieldKeys.Item.Annotation.Position.paths, key: key) } paths = parsedPaths continue case FieldKeys.Item.Annotation.Position.rects: - guard let parsedRects = object.value as? [[Double]], !parsedRects.isEmpty && parsedRects.contains(where: { $0.count != 4 }) else { + guard let parsedRects = object.value as? [[Double]], !parsedRects.isEmpty && !parsedRects.contains(where: { $0.count != 4 }) else { throw SchemaError.invalidValue(value: "\(object.value)", field: FieldKeys.Item.Annotation.Position.rects, key: key) } rects = parsedRects diff --git a/Zotero/Scenes/Detail/Lookup/Views/ManualLookupViewController.swift b/Zotero/Scenes/Detail/Lookup/Views/ManualLookupViewController.swift index af2b5dff5..c9ab5f560 100644 --- a/Zotero/Scenes/Detail/Lookup/Views/ManualLookupViewController.swift +++ b/Zotero/Scenes/Detail/Lookup/Views/ManualLookupViewController.swift @@ -129,7 +129,7 @@ class ManualLookupViewController: UIViewController { self.setupCloseBarButton(title: L10n.cancel) case .lookup(let data): - let didTranslateAll = data.contains(where: { data in + let didTranslateAll = !data.contains(where: { data in switch data.state { case .enqueued, .inProgress: return true case .failed, .translated: return false diff --git a/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift b/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift index c9be91408..1977043bf 100644 --- a/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift +++ b/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift @@ -400,7 +400,7 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi // } // private func selectedAnnotationsDeletable(selected: Set, in viewModel: ViewModel) -> Bool { - return selected.contains(where: { key in + return !selected.contains(where: { key in guard let annotation = viewModel.state.annotation(for: key) else { return false } return !annotation.isSyncable || annotation.editability(currentUserId: viewModel.state.userId, library: viewModel.state.library) == .notEditable }) @@ -848,7 +848,7 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi for (_, annotations) in viewModel.state.document.allAnnotations(of: PSPDFKit.Annotation.Kind.all) { for annotation in annotations { - let isHidden = filteredKeys.contains(where: { $0.key == (annotation.key ?? annotation.uuid) }) + let isHidden = !filteredKeys.contains(where: { $0.key == (annotation.key ?? annotation.uuid) }) if isHidden && !annotation.flags.contains(.hidden) { annotation.flags.update(with: .hidden) NotificationCenter.default.post(name: .PSPDFAnnotationChanged, object: annotation, userInfo: [PSPDFAnnotationChangedNotificationKeyPathKey: ["flags"]]) diff --git a/Zotero/Scenes/General/ViewModels/TagPickerActionHandler.swift b/Zotero/Scenes/General/ViewModels/TagPickerActionHandler.swift index 53e7177ed..cb5093c7a 100644 --- a/Zotero/Scenes/General/ViewModels/TagPickerActionHandler.swift +++ b/Zotero/Scenes/General/ViewModels/TagPickerActionHandler.swift @@ -74,7 +74,7 @@ struct TagPickerActionHandler: ViewModelActionHandler { state.searchTerm = term state.tags = (state.snapshot ?? state.tags).filter({ $0.name.localizedCaseInsensitiveContains(term) }) state.changes = .tags - state.showAddTagButton = state.tags.isEmpty || state.tags.contains(where: { $0.name == term }) + state.showAddTagButton = state.tags.isEmpty || !state.tags.contains(where: { $0.name == term }) } } else { guard let snapshot = viewModel.state.snapshot else { return } diff --git a/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift b/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift index c6fd770ee..1ff1f54a6 100644 --- a/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift +++ b/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift @@ -59,12 +59,12 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject { let snapshot = self.dataSource.snapshot(for: self.collectionsSection) - if snapshot.items.contains(where: { $0.identifier == collectionId }) { + if !snapshot.items.contains(where: { $0.identifier == collectionId }) { // Collection is not stored in this snapshot, nothing to select. return } - if snapshot.visibleItems.contains(where: { $0.identifier == collectionId }) { + if !snapshot.visibleItems.contains(where: { $0.identifier == collectionId }) { // Selection is collapsed, we need to expand and select it then self.update(with: tree, selectedId: collectionId, animated: false) { [weak self] in self?.selectIfNeeded(collectionId: collectionId, tree: tree, scrollToPosition: scrollToPosition)