Skip to content

Commit

Permalink
Merge pull request #877 from Infomaniak/swift-format
Browse files Browse the repository at this point in the history
refactor: Apply SwiftFormat everywhere
  • Loading branch information
valentinperignon committed Jul 13, 2023
2 parents 3737cd8 + a97cd35 commit 2005196
Show file tree
Hide file tree
Showing 78 changed files with 182 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Mail/Components/InitialsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import SwiftUI
import MailResources
import SwiftUI

struct InitialsView: View {
var initials: String
Expand Down
5 changes: 2 additions & 3 deletions Mail/Components/LargePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct LargePicker<SelectionValue, ButtonType>: View where SelectionValue: Hasha

var body: some View {
VStack(alignment: .leading, spacing: 4) {
if let title = title {
if let title {
Text(title)
.textStyle(.bodySmall)
}
Expand Down Expand Up @@ -87,10 +87,9 @@ extension LargePicker where ButtonType == EmptyView {
self.title = title
self.noSelectionText = noSelectionText
self.items = items
self.button = nil
button = nil
_selection = selection
}

}

struct LargePicker_Previews: PreviewProvider {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Components/LoadingButtonProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import SwiftUI

struct LoadingButtonProgressView: View {
private let tintColor: Color?

init(style: MailButton.Style) {
tintColor = style == .large ? .white : nil
}
Expand Down
2 changes: 1 addition & 1 deletion Mail/Components/MoreRecipientsChip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import SwiftUI
import MailCore
import SwiftUI

extension EdgeInsets {
init(uiEdgeInsets insets: UIEdgeInsets) {
Expand Down
4 changes: 2 additions & 2 deletions Mail/Components/ThreadCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ struct ThreadCell: View {
if isEnabled {
// We should wait a bit before showing the checkbox
DispatchQueue.main.asyncAfter(deadline: .now() + UIConstants.checkboxAppearDelay) {
self.shouldDisplayCheckbox = true
shouldDisplayCheckbox = true
}
} else {
self.shouldDisplayCheckbox = false
shouldDisplayCheckbox = false
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Mail/Helpers/DocumentPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ struct DocumentPicker: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let picker: UIDocumentPickerViewController
switch pickerType {
case let .selectContent(types, _):
case .selectContent(let types, _):
picker = UIDocumentPickerViewController(forOpeningContentTypes: types, asCopy: true)
picker.allowsMultipleSelection = true
case let .exportContent(urls):
case .exportContent(let urls):
picker = UIDocumentPickerViewController(forExporting: urls, asCopy: true)
}

Expand All @@ -63,7 +63,7 @@ struct DocumentPicker: UIViewControllerRepresentable {
}

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
if case let .selectContent(_, completion) = parent.pickerType {
if case .selectContent(_, let completion) = parent.pickerType {
completion(urls)
}
parent.dismiss()
Expand Down
2 changes: 1 addition & 1 deletion Mail/Helpers/RichTextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct RichTextEditor: UIViewRepresentable {
if becomeFirstResponder {
DispatchQueue.main.async {
uiView.setBecomeFirstResponder()
self.becomeFirstResponder = false
becomeFirstResponder = false
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mail/LockedAppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct LockedAppView: View {

private func unlockApp() {
Task {
if (try? await appLockHelper.evaluatePolicy(reason: MailResourcesStrings.Localizable.lockAppTitle)) == true {
if await (try? appLockHelper.evaluatePolicy(reason: MailResourcesStrings.Localizable.lockAppTitle)) == true {
appLockHelper.setTime()
Task {
navigationState.transitionToRootViewDestination(.mainView)
Expand Down
2 changes: 1 addition & 1 deletion Mail/MailApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct MailApp: App {
}

func updateUI(accent: AccentColor, theme: Theme) {
let allWindows = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.flatMap { $0.windows }
let allWindows = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.flatMap(\.windows)
for window in allWindows {
window.tintColor = accent.primary.color
window.overrideUserInterfaceStyle = theme.interfaceStyle
Expand Down
2 changes: 1 addition & 1 deletion Mail/Utils/DraftUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import MailCore
import SwiftUI

@MainActor
class DraftUtils {
enum DraftUtils {
public static func editDraft(from thread: Thread, mailboxManager: MailboxManager, editedMessageDraft: Binding<Draft?>) {
guard let message = thread.messages.first else { return }
// If we already have the draft locally, present it directly
Expand Down
2 changes: 1 addition & 1 deletion Mail/Utils/FilterCellModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI
import MailCore

struct FilterCellModifier: ViewModifier {
@AppStorage(UserDefaults.shared.key(.accentColor)) private var accentColor = DefaultPreferences.accentColor
Expand Down
1 change: 0 additions & 1 deletion Mail/Utils/FloatingActionButtonModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ struct FloatingActionButtonModifier: ViewModifier {
.onPreferenceChange(ViewHeightKey.self) { value in
snackBarAwareModifier.inset = value
}

}
}
.ignoresSafeArea(.keyboard)
Expand Down
10 changes: 5 additions & 5 deletions Mail/Utils/Formatters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ import Foundation
public extension Date {
var customRelativeFormatted: String {
if self > .now {
return self.formatted(date: .numeric, time: .omitted)
return formatted(date: .numeric, time: .omitted)
} else if Calendar.current.isDateInToday(self) {
return self.formatted(date: .omitted, time: .shortened)
return formatted(date: .omitted, time: .shortened)
} else if Calendar.current.isDateInYesterday(self) {
let dateMidnight = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
return dateMidnight.formatted(.relative(presentation: .named))
} else if let lastWeek = Calendar.current.date(byAdding: .day, value: -7, to: Date()), self > lastWeek {
return self.formatted(.dateTime.weekday(.wide))
return formatted(.dateTime.weekday(.wide))
} else if Calendar.current.isDate(self, equalTo: .now, toGranularity: .year) {
return self.formatted(.dateTime.day().month())
return formatted(.dateTime.day().month())
} else {
return self.formatted(date: .numeric, time: .omitted)
return formatted(date: .numeric, time: .omitted)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Mail/Utils/IlluColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ extension AnimationKeypath {
case border = "Contour"
}

static func keyPath(category: Category, categoryNumber: Int? = nil, group: Int = 1, finalLayer: FinalLayer = .background) -> Self {
static func keyPath(category: Category, categoryNumber: Int? = nil, group: Int = 1,
finalLayer: FinalLayer = .background) -> Self {
var categoryName = category.rawValue
if let categoryNumber {
categoryName = "\(categoryName) \(categoryNumber)"
Expand Down
6 changes: 3 additions & 3 deletions Mail/Utils/NavigationBarStyleViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ struct NavigationBarStyleViewModifier: ViewModifier {

func body(content: Content) -> some View {
content
.introspectNavigationController { navigationController in
guard self.navigationViewController != navigationController else {
.introspectNavigationController { navigationViewController in
guard self.navigationViewController != navigationViewController else {
return
}
self.navigationViewController = navigationController
self.navigationViewController = navigationViewController
updateAppearanceNavigationController()
}
.onAppear {
Expand Down
9 changes: 4 additions & 5 deletions Mail/Utils/View+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ extension View {
}

func emptyState<T>(isEmpty: Bool, @ViewBuilder emptyView: () -> T) -> some View where T: View {
self
.overlay {
if isEmpty {
emptyView()
}
overlay {
if isEmpty {
emptyView()
}
}
}
}
3 changes: 2 additions & 1 deletion Mail/Views/Alerts/CreateFolderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import SwiftUI

struct CreateFolderView: View {
@EnvironmentObject private var mailboxManager: MailboxManager
// swiftlint:disable empty_count
// swiftlint:disable:next empty_count
@ObservedResults(Folder.self, where: { $0.parents.count == 0 }) private var folders

@State private var folderName = ""
Expand Down Expand Up @@ -112,6 +112,7 @@ struct CreateFolderView: View {
let trimmedName = newName.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmedName.count >= Constants.maxFolderNameLength {
error = .nameTooLong
// swiftlint:disable:next empty_count
} else if trimmedName.lowercased() == "inbox" || folders.where({ $0.name == trimmedName }).count > 0 {
error = .nameAlreadyExists
} else {
Expand Down
8 changes: 4 additions & 4 deletions Mail/Views/Bottom sheets/Actions/ActionUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import Foundation
import InfomaniakCoreUI
import MailResources
import MailCore
import MailResources

struct ActionUtils {
let actionsTarget: ActionsTarget
Expand All @@ -42,9 +42,9 @@ struct ActionUtils {
}

await IKSnackBar.showCancelableSnackBar(message: snackBarMessage,
cancelSuccessMessage: MailResourcesStrings.Localizable.snackbarMoveCancelled,
undoRedoAction: undoRedoAction,
mailboxManager: mailboxManager)
cancelSuccessMessage: MailResourcesStrings.Localizable.snackbarMoveCancelled,
undoRedoAction: undoRedoAction,
mailboxManager: mailboxManager)
}

func move(to folderRole: FolderRole) async throws {
Expand Down
4 changes: 2 additions & 2 deletions Mail/Views/Bottom sheets/Actions/ActionsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ struct Action: Identifiable, Equatable {
enum ActionsTarget: Equatable, Identifiable {
var id: String {
switch self {
case .threads(let threads, let isMultiSelectionEnabled):
return threads.map { $0.id }.joined()
case .threads(let threads, _):
return threads.map(\.id).joined()
case .message(let message):
return message.uid
}
Expand Down
6 changes: 3 additions & 3 deletions Mail/Views/Bottom sheets/Actions/ReplyActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ struct ReplyActionsView: View {
message: Message,
messageReply: Binding<MessageReply?>?) {
_viewModel = StateObject(wrappedValue: ActionsViewModel(mailboxManager: mailboxManager,
target: .message(message),
messageReply: messageReply,
matomoCategory: .replyBottomSheet))
target: .message(message),
messageReply: messageReply,
matomoCategory: .replyBottomSheet))
}

var body: some View {
Expand Down
4 changes: 2 additions & 2 deletions Mail/Views/Bottom sheets/Actions/ReportJunkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct ReportJunkView: View {
target: ActionsTarget,
reportedForPhishingMessage: Binding<Message?>) {
_viewModel = StateObject(wrappedValue: ActionsViewModel(mailboxManager: mailboxManager,
target: target,
reportedForPhishingMessage: reportedForPhishingMessage))
target: target,
reportedForPhishingMessage: reportedForPhishingMessage))
if case .message(let message) = target {
let spam = message.folder?.role == .spam
actions.append(contentsOf: [
Expand Down
5 changes: 4 additions & 1 deletion Mail/Views/Menu Drawer/Actions/HelpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct HelpView: View {
let destination: URL

static let faq = HelpAction(title: MailResourcesStrings.Localizable.helpFAQ, destination: URLConstants.faq.url)
static let chatbot = HelpAction(title: MailResourcesStrings.Localizable.helpChatbot, destination: URLConstants.chatbot.url)
static let chatbot = HelpAction(
title: MailResourcesStrings.Localizable.helpChatbot,
destination: URLConstants.chatbot.url
)
}

@Environment(\.openURL) var openURL
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Menu Drawer/FolderListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class FolderListViewModel: ObservableObject {
}

func updateFolderListForMailboxManager(_ mailboxManager: MailboxManager, animateInitialChanges: Bool) {
// swiftlint:disable empty_count
foldersObservationToken = mailboxManager.getRealm()
// swiftlint:disable:next empty_count
.objects(Folder.self).where { $0.parents.count == 0 && $0.toolType == nil }
.observe(on: DispatchQueue.main) { [weak self] results in
switch results {
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 @@ -80,7 +80,7 @@ struct FolderCell: View {
}
splitViewManager.selectedFolder = folder.content
splitViewManager.showSearch = false
self.shouldTransit = true
shouldTransit = true
} label: {
FolderCellContent(
folder: folder.content,
Expand Down
6 changes: 4 additions & 2 deletions Mail/Views/New Message/Attachments/AttachmentUploadCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct AttachmentUploadCell: View {
}

Button {
if let attachmentRemoved = attachmentRemoved {
if let attachmentRemoved {
attachmentRemoved(attachment)
}
} label: {
Expand Down Expand Up @@ -74,6 +74,8 @@ struct AttachmentUploadCell: View {

struct AttachmentUploadCell_Previews: PreviewProvider {
static var previews: some View {
AttachmentUploadCell(attachment: PreviewHelper.sampleAttachment, uploadTask: AttachmentUploadTask()) { _ in /* Preview */ }
AttachmentUploadCell(attachment: PreviewHelper.sampleAttachment, uploadTask: AttachmentUploadTask()) { _ in
/* Preview */
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ struct AttachmentsHeaderView: View {
HStack(spacing: 8) {
ForEach(attachmentsManager.attachments) { attachment in
AttachmentUploadCell(attachment: attachment,
uploadTask: attachmentsManager.attachmentUploadTaskOrFinishedTask(for: attachment.uuid)) { attachmentRemoved in
uploadTask: attachmentsManager
.attachmentUploadTaskOrFinishedTask(for: attachment
.uuid)) { attachmentRemoved in
attachmentsManager.removeAttachment(attachmentRemoved)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class AttachmentsManager: ObservableObject {
do {
let url = try await attachment.writeToTemporaryURL()
let updatedAttachment = await updateLocalAttachment(url: url, attachment: localAttachment)
let totalSize = attachments.map { $0.size }.reduce(0) { $0 + $1 }
let totalSize = attachments.map(\.size).reduce(0) { $0 + $1 }
guard totalSize < Constants.maxAttachmentsSize else {
globalError = MailError.attachmentsSizeLimitReached
removeAttachment(updatedAttachment)
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/New Message/AutocompletionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AutocompletionCell: View {
RecipientCell(recipient: recipient, highlight: highlight)
}
}
.allowsHitTesting(!alreadyAppend || unknownRecipient)
.allowsHitTesting(!alreadyAppend || unknownRecipient)
.opacity(alreadyAppend && !unknownRecipient ? 0.5 : 1)

if alreadyAppend && !unknownRecipient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct ComposeMessageCellStaticText: View {
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, UIConstants.composeViewHeaderCellLargeVerticalSpacing)

IKDivider()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct ComposeMessageCellTextField: View {
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, UIConstants.composeViewHeaderCellLargeVerticalSpacing)

IKDivider()
}
.onTapGesture {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/New Message/RecipientField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct RecipientField: View {
}

private var isCurrentFieldFocused: Bool {
if case let .chip(hash, _) = focusedField {
if case .chip(let hash, _) = focusedField {
return type.hashValue == hash
}
return type == focusedField
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/New Message/Recipients/FullRecipientsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct FullRecipientsList: View {
}

private func switchFocus() {
guard case let .chip(hash, recipient) = focusedField else { return }
guard case .chip(let hash, let recipient) = focusedField else { return }

if recipient == recipients.last {
focusedField = type
Expand Down
Loading

0 comments on commit 2005196

Please sign in to comment.