Skip to content

Commit

Permalink
Fix bugs introduced when applied "contains_over_first_not_nil" lint r…
Browse files Browse the repository at this point in the history
…ule (#704)
  • Loading branch information
mvasilak authored Jun 22, 2023
1 parent 5dedef4 commit 7c9a6bc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Zotero/Models/API/ItemResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi
// }
//
private func selectedAnnotationsDeletable(selected: Set<PDFReaderState.AnnotationKey>, in viewModel: ViewModel<PDFReaderActionHandler>) -> 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
})
Expand Down Expand Up @@ -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"]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7c9a6bc

Please sign in to comment.