Skip to content

Commit

Permalink
chore: Reduce warnings (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann authored Sep 18, 2024
2 parents af96ae5 + 8903dc7 commit ed4ed1f
Show file tree
Hide file tree
Showing 43 changed files with 100 additions and 87 deletions.
1 change: 1 addition & 0 deletions Mail/Components/ThreadCell/ThreadCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct ThreadCellDataHolder {
let isInWrittenByMeFolder: Bool

init(thread: Thread) {
// swiftlint:disable:next last_where
let lastMessageNotFromSent = thread.messages.filter(Self.lastMessageNotFromSentPredicate).last ?? thread.messages.last

date = thread.date.formatted(.thread(.list))
Expand Down
13 changes: 7 additions & 6 deletions Mail/Views/AI Writer/Proposition/AIDismissibleErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ struct AIDismissibleErrorView: View {
InformationBlockView(
icon: MailResourcesAsset.warningFill.swiftUIImage,
message: error?.localizedDescription ?? "",
iconColor: MailResourcesAsset.orangeColor.swiftUIColor
) {
matomo.track(eventWithCategory: .aiWriter, name: "dismissError")
iconColor: MailResourcesAsset.orangeColor.swiftUIColor,
dismissHandler: { // swiftlint:disable:this trailing_closure
matomo.track(eventWithCategory: .aiWriter, name: "dismissError")

withAnimation {
isShowingError = false
withAnimation {
isShowingError = false
}
}
}
)
}
}
.onChange(of: error) { newError in
Expand Down
4 changes: 2 additions & 2 deletions Mail/Views/Bottom sheets/Actions/HeaderCloseButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct HeaderCloseButtonView: View {
}
}

#Preview {
@available(iOS 17.0, *)
#Preview(traits: .sizeThatFitsLayout) {
HeaderCloseButtonView(title: "View") {}
.previewLayout(.sizeThatFits)
}
1 change: 1 addition & 0 deletions Mail/Views/Menu Drawer/Actions/HelpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct HelpView: View {
.background(MailResourcesAsset.backgroundColor.swiftUIColor)
.navigationBarTitle(MailResourcesStrings.Localizable.buttonHelp, displayMode: .inline)
.customAlert(item: $updateVersionAlert) { action in
// swiftlint:disable:next trailing_closure
UpdateVersionAlertView(onLaterPressed: {
openURL(action.destination)
})
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Menu Drawer/Folders/FolderCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import SwiftUI
import SwiftUIMacros

extension EnvironmentValues {
@EnvironmentValue
@EnvironmentKey
var folderCellType = FolderCell.CellType.menuDrawer
}

Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Menu Drawer/MailboxManagement/MailboxCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import SwiftUI
import SwiftUIMacros

extension EnvironmentValues {
@EnvironmentValue
@EnvironmentKey
var mailboxCellStyle = MailboxCell.Style.menuDrawer
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct SettingsAccountManagementView: View {
}
}

extension ApiToken: Identifiable {
extension ApiToken: @retroactive Identifiable {
public var id: String {
return "\(userId)\(accessToken)"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct SettingsNotificationsView: View {
}
}
}
// swiftlint:disable:next trailing_closure
.sceneLifecycle(willEnterForeground: {
settingsNotificationEnabled { enabled in
showWarning = !enabled
Expand Down
1 change: 1 addition & 0 deletions Mail/Views/SplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ struct SplitView: View {
SafariWebView(url: safariContent.url)
.ignoresSafeArea()
}
// swiftlint:disable:next trailing_closure
.sceneLifecycle(willEnterForeground: {
Task {
// We need to write in Task instead of async let to avoid being cancelled to early
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import MailCoreUI
import MailResources
import SwiftUI

extension MailResourcesImages: Identifiable {
extension MailResourcesImages: @retroactive Identifiable {
public var id: String {
name
}
Expand Down
15 changes: 7 additions & 8 deletions Mail/Views/Thread List/ThreadListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ struct ThreadListCell: View {
density: threadDensity,
accentColor: accentColor,
isMultipleSelectionEnabled: multipleSelectionViewModel.isEnabled,
isSelected: isMultiSelected,
avatarTapped: {
if multipleSelectionViewModel.isEnabled {
didTapCell()
} else {
didOptionalTapCell()
}
isSelected: isMultiSelected
) {
if multipleSelectionViewModel.isEnabled {
didTapCell()
} else {
didOptionalTapCell()
}
)
}
.background(SelectionBackground(
selectionType: selectionType,
paddingLeading: 4,
Expand Down
2 changes: 2 additions & 0 deletions Mail/Views/Thread List/ThreadListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ struct ThreadListView: View {
.onChange(of: multipleSelectionViewModel.isEnabled) { isEnabled in
scrollObserver.shouldObserve = !isEnabled
}
// swiftlint:disable:next trailing_closure
.sceneLifecycle(willEnterForeground: {
updateFetchingTask()
})
Expand All @@ -210,6 +211,7 @@ struct ThreadListView: View {
FlushFolderAlertView(flushAlert: item, folder: viewModel.frozenFolder)
}
.customAlert(isPresented: $isShowingUpdateAlert) {
// swiftlint:disable:next trailing_closure
UpdateVersionAlertView(onDismiss: {
hasDismissedUpdateVersionView = true
})
Expand Down
6 changes: 4 additions & 2 deletions Mail/Views/Thread/Message/InlineAttachmentWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ final class InlineAttachmentWorker: ObservableObject {

self.mailboxManager = mailboxManager
processing = Task { [weak self] in
guard let message = mailboxManager.transactionExecutor.fetchObject(ofType: Message.self, forPrimaryKey: messageUid)?
.freeze() else {
guard let message = mailboxManager.transactionExecutor.fetchObject(
ofType: Message.self,
forPrimaryKey: self?.messageUid
)?.freeze() else {
return
}

Expand Down
20 changes: 11 additions & 9 deletions Mail/Views/Thread/Message/MessageBodyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ struct MessageBodyView: View {
}

if !presentableBody.quotes.isEmpty {
Button(model.showBlockQuote
? MailResourcesStrings.Localizable.messageHideQuotedText
: MailResourcesStrings.Localizable.messageShowQuotedText) {
model.showBlockQuote.toggle()
}
.buttonStyle(.ikBorderless(isInlined: true))
.controlSize(.small)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, value: .medium)
Button(
model.showBlockQuote
? MailResourcesStrings.Localizable.messageHideQuotedText
: MailResourcesStrings.Localizable.messageShowQuotedText
) {
model.showBlockQuote.toggle()
}
.buttonStyle(.ikBorderless(isInlined: true))
.controlSize(.small)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, value: .medium)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,22 @@ struct MessageHeaderSummaryView: View {
}
}

#Preview("Message collapsed") {
MessageHeaderSummaryView(message: PreviewHelper.sampleMessage,
isMessageExpanded: .constant(false),
isHeaderExpanded: .constant(false)) {
// Preview
}
.environmentObject(PreviewHelper.sampleMailboxManager)
.previewLayout(.sizeThatFits)
@available(iOS 17.0, *)
#Preview("Message collapsed", traits: .sizeThatFitsLayout) {
MessageHeaderSummaryView(
message: PreviewHelper.sampleMessage,
isMessageExpanded: .constant(false),
isHeaderExpanded: .constant(false)
) {}
.environmentObject(PreviewHelper.sampleMailboxManager)
}

#Preview("Message expanded") {
MessageHeaderSummaryView(message: PreviewHelper.sampleMessage,
isMessageExpanded: .constant(true),
isHeaderExpanded: .constant(false)) {
// Preview
}
.environmentObject(PreviewHelper.sampleMailboxManager)
.previewLayout(.sizeThatFits)
@available(iOS 17.0, *)
#Preview("Message expanded", traits: .sizeThatFitsLayout) {
MessageHeaderSummaryView(
message: PreviewHelper.sampleMessage,
isMessageExpanded: .constant(true),
isHeaderExpanded: .constant(false)
) {}
.environmentObject(PreviewHelper.sampleMailboxManager)
}
8 changes: 4 additions & 4 deletions Mail/Views/Thread/Message/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,20 @@ extension MessageView {
}
}

#Preview("Message collapsed") {
@available(iOS 17.0, *)
#Preview("Message collapsed", traits: .sizeThatFitsLayout) {
MessageView(
message: PreviewHelper.sampleMessage,
threadForcedExpansion: .constant([PreviewHelper.sampleMessage.uid: .collapsed])
)
.environmentObject(PreviewHelper.sampleMailboxManager)
.previewLayout(.sizeThatFits)
}

#Preview("Message expanded") {
@available(iOS 17.0, *)
#Preview("Message expanded", traits: .sizeThatFitsLayout) {
MessageView(
message: PreviewHelper.sampleMessage,
threadForcedExpansion: .constant([PreviewHelper.sampleMessage.uid: .expanded])
)
.environmentObject(PreviewHelper.sampleMailboxManager)
.previewLayout(.sizeThatFits)
}
2 changes: 1 addition & 1 deletion Mail/Views/Thread/SuperCollapsedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ struct SuperCollapsedView: View {
}

#Preview {
SuperCollapsedView(count: 5, action: {})
SuperCollapsedView(count: 5) {}
}
5 changes: 2 additions & 3 deletions MailCore/API/MailApiFetcher/MailApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public final class MailApiFetcher: ApiFetcher, MailApiFetchable {
if case .responseSerializationFailed(let reason) = afError, case .decodingFailed(let error) = reason,
let statusCode = request.response?.statusCode, (200 ... 299).contains(statusCode) {
var rawJson = "No data"
if let data = request.data,
let stringData = String(data: data, encoding: .utf8) {
rawJson = stringData
if let data = request.data {
rawJson = String(decoding: data, as: UTF8.self)
}

SentrySDK.capture(error: error) { scope in
Expand Down
2 changes: 1 addition & 1 deletion MailCore/API/MailError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation
import InfomaniakCore
import MailResources

extension ApiError: CustomStringConvertible {}
extension ApiError: @retroactive CustomStringConvertible {}

public class AFErrorWithContext: MailError, CustomStringConvertible {
public let request: DataRequest
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/Actions/Action+List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension Action: CaseIterable {
let star = message.flagged
let spam = message.folder?.role == .spam
let print = origin.type == .floatingPanel(source: .messageList)
var tempListActions: [Action?] = [
let tempListActions: [Action?] = [
.openMovePanel,
spam ? .nonSpam : .reportJunk,
unread ? .markAsRead : .markAsUnread,
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/Actions/ActionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import MailResources
import Sentry
import SwiftUI

extension [Message]: Identifiable {
extension [Message]: @retroactive Identifiable {
public var id: Int {
var hasher = Hasher()
forEach { hasher.combine($0.hashValue) }
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/DraftManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ actor DraftQueue {
func beginBackgroundTask(withName name: String, for uuid: String) async {
let identifier = await UIApplication.shared.beginBackgroundTask(withName: name) { [self] in
Task {
endBackgroundTask(uuid: uuid)
await endBackgroundTask(uuid: uuid)
}
}
identifierQueue[uuid] = identifier
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/MailboxManager/MailboxManageable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ public protocol MailboxManagerAttachable {
func swissTransferAttachment(message: Message) async throws
}

// TODO: write a dedicated protocol for each MailboxManager+<>
// TODO: write a dedicated protocol for each MailboxManager
2 changes: 1 addition & 1 deletion MailCore/Cache/MailboxManager/MailboxManager+Folders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public extension MailboxManager {
}

func createFolder(name: String, parent: Folder?) async throws -> Folder {
var folder = try await apiFetcher.create(mailbox: mailbox, folder: NewFolder(name: name, path: parent?.path))
let folder = try await apiFetcher.create(mailbox: mailbox, folder: NewFolder(name: name, path: parent?.path))
try writeTransaction { writableRealm in
writableRealm.add(folder)
if let parent {
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Utils/ContentRuleGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public enum ContentRuleGenerator {

public static func generateContentRulesJSON(rules: [ContentRule]) -> String? {
guard let encodedData = try? jsonEncoder.encode(rules) else { return nil }
return String(data: encodedData, encoding: .utf8)
return String(decoding: encodedData, as: UTF8.self)
}
}
2 changes: 1 addition & 1 deletion MailCore/Utils/LocalContactsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final class LocalContactsHelper: LocalContactsHelpable {

private func checkAuthorization() async throws {
switch CNContactStore.authorizationStatus(for: .contacts) {
case .authorized:
case .authorized, .limited:
// All ok
return
case .restricted, .denied:
Expand Down
1 change: 0 additions & 1 deletion MailCore/Utils/MessageBodyUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import CocoaLumberjackSwift
import Foundation
import MailCore
import MailResources
import SwiftSoup

Expand Down
6 changes: 3 additions & 3 deletions MailCoreUI/Components/InformationBlockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public struct InformationBlockView: View {
message: "Tip",
iconColor: .blue,
buttonAction: {},
buttonTitle: "Button title"
) {
/* Preview */ }
buttonTitle: "Button title",
dismissHandler: {} // swiftlint:disable:this trailing_closure
)
}

#Preview("Without Title") {
Expand Down
2 changes: 1 addition & 1 deletion MailCoreUI/Extensions/Environment+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import SwiftUI
import SwiftUIMacros

public extension EnvironmentValues {
@EnvironmentValue
@EnvironmentKey
var isCompactWindow = true
}
2 changes: 1 addition & 1 deletion MailCoreUI/ViewModifier/SheetViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import SwiftUIMacros
public typealias DismissModalAction = () -> Void

public extension EnvironmentValues {
@EnvironmentValue
@EnvironmentKey
var dismissModal: DismissModalAction = { /* dismiss nothing by default */ }
}

Expand Down
3 changes: 2 additions & 1 deletion MailShareExtension/ComposeMessageWrapperView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import MobileCoreServices
import Social
import SwiftUI
import UIKit
import UniformTypeIdentifiers
import VersionChecker

struct ComposeMessageWrapperView: View {
Expand All @@ -39,7 +40,7 @@ struct ComposeMessageWrapperView: View {
let itemProviders: [NSItemProvider]
let dismissHandler: SimpleClosure

static let typePropertyList = String(kUTTypePropertyList)
static let typePropertyList = UTType.propertyList.identifier

/// All the Attachments that should directly provide URLs and title for a new Email Draft
var htmlAttachments: [HTMLAttachable] {
Expand Down
2 changes: 1 addition & 1 deletion MailTests/Contacts/UTContactManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import XCTest
final class UTContactManager: XCTestCase {
let contactManager = ContactManager(userId: 0, apiFetcher: MailApiFetcher())

override class func setUp() {
override static func setUp() {
super.setUp()

MockingHelper.clearRegisteredTypes()
Expand Down
Loading

0 comments on commit ed4ed1f

Please sign in to comment.