lint fixes

This commit is contained in:
Satindar Dhillon
2022-06-16 22:14:45 -07:00
parent 726c11afd2
commit 6f86495cf4
19 changed files with 53 additions and 38 deletions

View File

@ -18,7 +18,10 @@ class ExtensionSaveService {
self.queue = OperationQueue()
}
private func queueSaveOperation(_ pageScrape: PageScrapePayload, shareExtensionViewModel: ShareExtensionChildViewModel) {
private func queueSaveOperation(
_ pageScrape: PageScrapePayload,
shareExtensionViewModel: ShareExtensionChildViewModel
) {
ProcessInfo().performExpiringActivity(withReason: "app.omnivore.SaveActivity") { [self] expiring in
guard !expiring else {
self.queue.cancelAllOperations()
@ -85,6 +88,7 @@ class ExtensionSaveService {
var queue: OperationQueue?
var uploadTask: URLSessionTask?
// swiftlint:disable:next nesting
enum State: Int {
case created
case started

View File

@ -55,7 +55,12 @@ struct ShareExtensionView: View {
var body: some View {
ShareExtensionChildView(
viewModel: childViewModel,
onAppearAction: { viewModel.savePage(extensionContext: extensionContext, shareExtensionViewModel: childViewModel) },
onAppearAction: {
viewModel.savePage(
extensionContext: extensionContext,
shareExtensionViewModel: childViewModel
)
},
readNowButtonAction: { viewModel.handleReadNowAction(requestId: $0, extensionContext: extensionContext) },
dismissButtonTappedAction: { _, _ in
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)

View File

@ -2,6 +2,7 @@ import Combine
import SwiftUI
import Utils
// swiftlint:disable file_length
#if os(iOS)
import PSPDFKit
import PSPDFKitUI
@ -147,7 +148,7 @@ import Utils
pdfStateObject.document = document
pdfStateObject.coordinator = PDFViewCoordinator(document: document, viewModel: viewModel)
} else {
errorMessage = "Unable to download PDF: \(pdfURL)"
errorMessage = "Unable to download PDF: \(pdfURL?.description ?? "")"
}
}
}
@ -220,6 +221,7 @@ import Utils
return result
}
// swiftlint:disable:next function_body_length
func highlightSelection(pageView: PDFPageView, selectedText: String, dataService: DataService) -> String {
let highlightID = UUID().uuidString.lowercased()
let quote = quoteFromSelectedText(selectedText)

View File

@ -102,4 +102,5 @@ public final class Services {
#endif
// Command to simulate BG Task
// swiftlint:disable:next line_length
// e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"app.omnivore.fetchLinkedItems"]

View File

@ -5,6 +5,7 @@ import UserNotifications
import Utils
import Views
// swiftlint:disable file_length
#if os(iOS)
private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone
@ -196,7 +197,10 @@ import Views
}
.padding(.horizontal)
.sheet(isPresented: $showLabelsSheet) {
FilterByLabelsView(initiallySelected: viewModel.selectedLabels, initiallyNegated: viewModel.negatedLabels) {
FilterByLabelsView(
initiallySelected: viewModel.selectedLabels,
initiallyNegated: viewModel.negatedLabels
) {
self.viewModel.selectedLabels = $0
self.viewModel.negatedLabels = $1
}

View File

@ -73,6 +73,7 @@ import WebKit
return webView
}
// swiftlint:disable:next cyclomatic_complexity
func updateUIView(_ webView: WKWebView, context: Context) {
if annotationSaveTransactionID != context.coordinator.lastSavedAnnotationID {
context.coordinator.lastSavedAnnotationID = annotationSaveTransactionID

View File

@ -58,11 +58,17 @@ public extension LinkedItemFilter {
return NSCompoundPredicate(andPredicateWithSubpredicates: [undeletedPredicate, notInArchivePredicate])
case .readlater:
// non-archived or deleted items without the Newsletter label
let nonNewsletterLabelPredicate = NSPredicate(format: "NOT SUBQUERY(labels, $label, $label.name == \"Newsletter\") .@count > 0")
return NSCompoundPredicate(andPredicateWithSubpredicates: [undeletedPredicate, notInArchivePredicate, nonNewsletterLabelPredicate])
let nonNewsletterLabelPredicate = NSPredicate(
format: "NOT SUBQUERY(labels, $label, $label.name == \"Newsletter\") .@count > 0"
)
return NSCompoundPredicate(andPredicateWithSubpredicates: [
undeletedPredicate, notInArchivePredicate, nonNewsletterLabelPredicate
])
case .newsletters:
// non-archived or deleted items with the Newsletter label
let newsletterLabelPredicate = NSPredicate(format: "SUBQUERY(labels, $label, $label.name == \"Newsletter\").@count > 0")
let newsletterLabelPredicate = NSPredicate(
format: "SUBQUERY(labels, $label, $label.name == \"Newsletter\").@count > 0"
)
return NSCompoundPredicate(andPredicateWithSubpredicates: [notInArchivePredicate, newsletterLabelPredicate])
case .all:
// include everything undeleted

View File

@ -256,20 +256,7 @@ private extension PageScrapePayload {
let localFile = UUID().uuidString.lowercased() + ".pdf"
dest.appendPathComponent(localFile)
do {
print("EXISTING PDF URL", url)
let attr = try? FileManager.default.attributesOfItem(atPath: url.path)
if let attr = attr {
print("EXISTING FILE SIZE", attr[.size])
}
try FileManager.default.copyItem(at: url, to: dest)
print("COPIED TO URL", dest)
let attr2 = try? FileManager.default.attributesOfItem(atPath: dest.path)
if let attr2 = attr2 {
print("COPIED FILE SIZE", attr2[.size])
}
return PageScrapePayload(url: url.absoluteString, localUrl: dest)
} catch {
print("error copying file locally", error)

View File

@ -122,6 +122,7 @@ public final class DataService: ObservableObject {
return isFirstRunOfVersion || isFirstRunWithBuildNumber
}
// swiftlint:disable:next function_body_length
public func persistPageScrapePayload(_ pageScrape: PageScrapePayload, requestId: String) async throws {
let normalizedURL = normalizeURL(pageScrape.url)

View File

@ -26,6 +26,7 @@ extension DataService {
}
}
// swiftlint:disable:next function_body_length
func syncLabelCreation(label: InternalLinkedItemLabel) {
enum MutationResult {
case saved(label: InternalLinkedItemLabel)

View File

@ -13,7 +13,9 @@ public extension DataService {
let selection = Selection<MutationResult, Unions.UnsubscribeResult> {
try $0.on(
unsubscribeError: .init { .error(errorMessage: (try $0.errorCodes().first ?? .unauthorized).rawValue) },
unsubscribeSuccess: .init { .success(id: try $0.subscription(selection: Selection.Subscription { try $0.id() })) }
unsubscribeSuccess: .init {
.success(id: try $0.subscription(selection: Selection.Subscription { try $0.id() }))
}
)
}

View File

@ -38,6 +38,7 @@ extension DataService {
return internalHighlight.encoded()
}
// swiftlint:disable:next function_body_length
func syncHighlightMerge(highlight: InternalHighlight, articleId: String, overlapHighlightIdList: [String]) {
enum MutationResult {
case saved(highlight: InternalHighlight)

View File

@ -84,8 +84,11 @@ public extension Networker {
}
public extension DataService {
// swiftlint:disable:next line_length
func saveArticlePublisher(pageScrapePayload: PageScrapePayload, uploadFileId: String?) -> AnyPublisher<Void, SaveArticleError> {
// swiftlint:disable:next function_body_length
func saveArticlePublisher(
pageScrapePayload: PageScrapePayload,
uploadFileId: String?
) -> AnyPublisher<Void, SaveArticleError> {
enum MutationResult {
case saved(created: Bool)
case error(errorCode: Enums.CreateArticleErrorCode)

View File

@ -11,6 +11,7 @@ public struct UploadFileRequestPayload {
}
public extension DataService {
// swiftlint:disable:next function_body_length
func uploadFileRequest(id: String, url: String) async throws -> UploadFileRequestPayload {
enum MutationResult {
case success(payload: UploadFileRequestPayload)
@ -60,11 +61,7 @@ public extension DataService {
switch payload.data {
case let .success(payload):
if let urlString = payload.urlString, let url = URL(string: urlString) {
continuation.resume(returning: payload)
} else {
continuation.resume(throwing: SaveArticleError.unknown(description: "No upload URL"))
}
continuation.resume(returning: payload)
case let .error(errorCode: errorCode):
switch errorCode {
case .unauthorized:
@ -85,12 +82,6 @@ public extension DataService {
request.httpMethod = "PUT"
request.addValue("application/pdf", forHTTPHeaderField: "content-type")
print("UPLOADING PDF", localPdfURL)
let attr = try? FileManager.default.attributesOfItem(atPath: localPdfURL.path)
if let attr = attr {
print("UPLOADING ATTR", attr[.size])
}
return try await withCheckedThrowingContinuation { continuation in
let task = networker.urlSession.uploadTask(with: request, fromFile: localPdfURL) { _, response, _ in
if let httpResponse = response as? HTTPURLResponse, 200 ... 299 ~= httpResponse.statusCode {

View File

@ -31,7 +31,7 @@ struct InternalLinkedItem {
if let contentReader = contentReader {
return contentReader == "PDF"
}
return (pageURLString ?? "").hasSuffix("pdf")
return pageURLString.hasSuffix("pdf")
}
func asManagedObject(inContext context: NSManagedObjectContext) -> LinkedItem {

View File

@ -40,7 +40,9 @@ public final class WebView: WKWebView {
}
public func updateMaxWidthPercentage() {
if let maxWidthPercentage = UserDefaults.standard.value(forKey: UserDefaultKey.preferredWebMaxWidthPercentage.rawValue) as? Int {
if let maxWidthPercentage = UserDefaults.standard.value(
forKey: UserDefaultKey.preferredWebMaxWidthPercentage.rawValue
) as? Int {
dispatchEvent(.updateMaxWidthPercentage(maxWidthPercentage: maxWidthPercentage))
}
}

View File

@ -46,7 +46,11 @@ struct CornerRadiusStyle: ViewModifier {
var corners = UIRectCorner.allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let path = UIBezierPath(
roundedRect: rect,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius)
)
return Path(path.cgPath)
}
}

View File

@ -14,6 +14,7 @@ final class UtilsTests: XCTestCase {
XCTAssertEqual(normalizeURL("https://omnivore.app/"), "https://omnivore.app")
// utm_ removed
// swiftlint:disable:next line_length
XCTAssertEqual(normalizeURL("https://omnivore.app/?aa=a&bb=b&utm_track=track&cc=c"), "https://omnivore.app?aa=a&bb=b&cc=c")
// query params sorted