Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add rules #995

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
--acronyms ID,URL,UUID
--allman false
--assetliterals visual-width
--asynccapturing
--beforemarks
--binarygrouping 4,8
--categorymark "MARK: %c"
--classthreshold 0
--closingparen balanced
--closurevoid remove
--commas always
--conflictmarkers reject
--decimalgrouping 3,6
--elseposition same-line
--emptybraces no-space
--enumnamespaces always
--enumthreshold 0
--exponentcase lowercase
--exponentgrouping disabled
--extensionacl on-extension
--extensionlength 0
--extensionmark "MARK: - %t + %c"
--fractiongrouping disabled
--fragment false
--funcattributes preserve
--generictypes
--groupedextension "MARK: %c"
--guardelse auto
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef no-indent
--importgrouping alpha
--indent 4
--indentcase false
--indentstrings false
--lifecycle
--lineaftermarks true
--linebreaks lf
--markcategories true
--markextensions always
--marktypes always
--maxwidth 130
--modifierorder
--nevertrailing
--nospaceoperators
--nowrapoperators
--octalgrouping 4,8
--operatorfunc spaced
--organizetypes actor,class,enum,struct
--patternlet inline
--ranges spaced
--redundanttype inferred
--self remove
--selfrequired
--semicolons inline
--shortoptionals always
--smarttabs enabled
--someany true
--stripunusedargs unnamed-only
--structthreshold 0
--tabwidth unspecified
--throwcapturing
--trailingclosures
--trimwhitespace always
--typeattributes preserve
--typeblanklines remove
--typemark "MARK: - %t"
--varattributes preserve
--voidtype void
--wraparguments preserve
--wrapcollections preserve
--wrapconditions preserve
--wrapeffects preserve
--wrapenumcases always
--wrapparameters default
--wrapreturntype preserve
--wrapternary default
--wraptypealiases preserve
--xcodeindentation disabled
--yodaswap always
--disable andOperator,opaqueGenericParameters,preferKeyPath,redundantReturn,strongOutlets,trailingCommas,unusedArguments,wrapMultilineStatementBraces
--enable blankLineAfterImports,blankLinesBetweenImports
Binary file added .swiftformat-bin/swiftformat
Binary file not shown.
3 changes: 2 additions & 1 deletion Mail/Components/RecipientChipLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class RecipientChipLabel: UILabel, UIKeyInput {
backgroundColor = isFirstResponder ? MailResourcesAsset.yellowColor.color : MailResourcesAsset.textFieldColor.color
} else {
textColor = isFirstResponder ? UserDefaults.shared.accentColor.secondary.color : .tintColor
borderColor = isFirstResponder ? UserDefaults.shared.accentColor.primary.color : UserDefaults.shared.accentColor.secondary.color
borderColor = isFirstResponder ? UserDefaults.shared.accentColor.primary.color : UserDefaults.shared.accentColor
.secondary.color
backgroundColor = isFirstResponder ? .tintColor : UserDefaults.shared.accentColor.secondary.color
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mail/Helpers/AppAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import MailCore
private let realmRootPath = "mailboxes"
private let appGroupIdentifier = "group.com.infomaniak.mail"

extension Array where Element == Factory {
extension [Factory] {
func registerFactoriesInDI() {
forEach { SimpleResolver.sharedResolver.store(factory: $0) }
}
Expand Down
2 changes: 1 addition & 1 deletion Mail/RootView.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

struct RootView: View {
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
Expand Down
2 changes: 1 addition & 1 deletion Mail/Utils/BackButtonDisplayModeModifier.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 SwiftUIIntrospect
import SwiftUI
import SwiftUIIntrospect

struct BackButtonDisplayModeModifier: ViewModifier {
let displayMode: UINavigationItem.BackButtonDisplayMode
Expand Down
2 changes: 1 addition & 1 deletion Mail/Utils/NavigationBarStyleViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct NavigationBarStyleViewModifier: ViewModifier {
func body(content: Content) -> some View {
content
.introspect(.viewController, on: .iOS(.v15, .v16, .v17)) { viewController in
self.navigationViewController = viewController.navigationController
navigationViewController = viewController.navigationController
updateAppearanceNavigationController()
}
.onAppear {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Utils/SegmentedControlModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import SwiftUIIntrospect
import MailCore
import MailResources
import SwiftUI
import SwiftUIIntrospect

struct SegmentedControlModifier: ViewModifier {
@AppStorage(UserDefaults.shared.key(.accentColor)) private var accentColor = DefaultPreferences.accentColor
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 @@ -48,7 +48,7 @@ struct NestableFolder: Identifiable {
for folder in folders {
parentFolders.append(NestableFolder(
content: folder,
children: Self.createFoldersHierarchy(from: Array(folder.children))
children: createFoldersHierarchy(from: Array(folder.children))
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import InfomaniakDI
import MailCore
import MailResources
import RealmSwift
import SwiftUI
import InfomaniakDI

struct ComposeMessageSenderMenu: View {
@EnvironmentObject private var draftContentManager: DraftContentManager

/// Note:
/// ObservedResults will invoke a `default.realm` store, and break (no migration block) while a migration is needed in share extension.
/// ObservedResults will invoke a `default.realm` store, and break (no migration block) while a migration is needed in share
/// extension.
///
/// Therefore, I have to pass the correct realm configuration for `Signature.self`, so it can function correctly.
@ObservedResults(Signature.self, configuration: {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/New Message/Header Cells/SenderMenuCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct SenderMenuCell: View {
matomo.track(eventWithCategory: .newMessage, name: "switchIdentity")

withAnimation {
self.currentSignature = signature
currentSignature = signature
}
draftContentManager.updateSignature(with: signature)
} label: {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Onboarding/SlideView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import InfomaniakCore
import InfomaniakCoreUI
import InfomaniakDI
import SwiftUIIntrospect
import Lottie
import MailCore
import MailResources
import SwiftUI
import SwiftUIIntrospect

struct SlideView: View {
let slide: Slide
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Search/SearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ enum SearchState {
observeSearch()

if searchValue.trimmingCharacters(in: .whitespacesAndNewlines).count >= 3 {
await mailboxManager.addToSearchHistory(value: searchValue)
await mailboxManager.addToSearchHistory(value: searchValue)
}
}

Expand Down
6 changes: 5 additions & 1 deletion Mail/Views/Settings/General/SettingsThreadModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ struct SettingsThreadModeView: View {
.settingsCell()

ForEach(ThreadMode.allCases, id: \.rawValue) { value in
SettingsOptionCell(value: value, isSelected: value == selectedValue, isLast: value == ThreadMode.allCases.last) {
SettingsOptionCell(
value: value,
isSelected: value == selectedValue,
isLast: value == ThreadMode.allCases.last
) {
if value != selectedValue {
threadModeSettingUpdate = ThreadModeSettingUpdate(newSetting: value)
}
Expand Down
6 changes: 5 additions & 1 deletion Mail/Views/Settings/Other/MailboxSignatureSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ struct MailboxSignatureSettingsView: View {
.settingsCell()

ForEach(signatures) { signature in
SettingsOptionCell(title: signature.name, isSelected: signature.isDefault, isLast: signature == signatures.last) {
SettingsOptionCell(
title: signature.name,
isSelected: signature.isDefault,
isLast: signature == signatures.last
) {
setAsDefault(signature)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Settings/SettingsSectionTitleView.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 MailResources
import MailCore
import MailResources
import SwiftUI

struct SettingsSectionTitleView: View {
Expand Down
2 changes: 1 addition & 1 deletion MailCore/API/NetworkRequestRetrier.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 Foundation
import Alamofire
import Foundation

final class NetworkRequestRetrier: RequestInterceptor {
let maxRetry: Int
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/ContactManager/ContactManager+Merge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extension ContactManager {
/// This will merge InfomaniakContact with local iPhone ones in a coherent DB.
/// Removed contacts from both datasets will be cleaned also
/// - Parameter remote: a list of remote infomaniak contacts
internal func updateContactDB(_ remote: [InfomaniakContact]) async {
func updateContactDB(_ remote: [InfomaniakContact]) async {
defer {
DDLogInfo("Done merging remote and local contacts in DB…")
}
Expand Down
4 changes: 2 additions & 2 deletions MailCore/Cache/ContactManager/ContactManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public final class ContactManager: ObservableObject {
backgroundRealm = BackgroundRealm(configuration: realmConfiguration)
}

internal let localContactsHelper = LocalContactsHelper()
internal var currentMergeRequest: Task<Void, Never>?
let localContactsHelper = LocalContactsHelper()
var currentMergeRequest: Task<Void, Never>?

// Entry point to refresh all contacts in base
public func refreshContactsAndAddressBooks() async throws {
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/DraftManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public final class DraftManager {
}

/// Check if once the Signature node is removed, we still have content
internal func isDraftBodyEmptyOfChanges(_ body: String) throws -> Bool {
func isDraftBodyEmptyOfChanges(_ body: String) throws -> Bool {
guard !body.isEmpty else {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions MailCore/Cache/MailboxManager/MailboxManageable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation
import RealmSwift

/// An abstract interface on the `MailboxManager`
public typealias MailboxManageable = MailBoxManagerMessageable & MailBoxManagerDraftable
public typealias MailboxManageable = MailBoxManagerDraftable & MailBoxManagerMessageable

/// An abstract interface on the `MailboxManager` related to messages
public protocol MailBoxManagerMessageable {
Expand Down Expand Up @@ -49,4 +49,4 @@ public protocol MailBoxManagerDraftable {
func deleteOrphanDrafts() async
}

// TODO write a dedicated protocol for each MailboxManager+<>
// TODO: write a dedicated protocol for each MailboxManager+<>
14 changes: 7 additions & 7 deletions MailCore/Cache/MailboxManager/MailboxManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import RealmSwift
import SwiftRegex

public final class MailboxManager: ObservableObject, MailboxManageable {
@LazyInjectService internal var snackbarPresenter: SnackBarPresentable
@LazyInjectService internal var mailboxInfosManager: MailboxInfosManager
@LazyInjectService var snackbarPresenter: SnackBarPresentable
@LazyInjectService var mailboxInfosManager: MailboxInfosManager

internal lazy var refreshActor = RefreshActor(mailboxManager: self)
internal let backgroundRealm: BackgroundRealm
lazy var refreshActor = RefreshActor(mailboxManager: self)
let backgroundRealm: BackgroundRealm

public static let constants = MailboxManagerConstants()

Expand Down Expand Up @@ -133,7 +133,7 @@ public final class MailboxManager: ObservableObject, MailboxManageable {
static let standard: MessagePropertiesOptions = [.fullyDownloaded, .body, .attachments, .localSafeDisplay]
}

internal func keepCacheAttributes(
func keepCacheAttributes(
for message: Message,
keepProperties: MessagePropertiesOptions,
using realm: Realm? = nil
Expand All @@ -157,7 +157,7 @@ public final class MailboxManager: ObservableObject, MailboxManageable {
}
}

internal func keepCacheAttributes(
func keepCacheAttributes(
for folder: Folder,
using realm: Realm
) {
Expand All @@ -170,7 +170,7 @@ public final class MailboxManager: ObservableObject, MailboxManageable {
folder.isExpanded = savedFolder.isExpanded
}

internal func getSubFolders(from folders: [Folder], oldResult: [Folder] = []) -> [Folder] {
func getSubFolders(from folders: [Folder], oldResult: [Folder] = []) -> [Folder] {
var result = oldResult
for folder in folders {
result.append(folder)
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Models/CommonContact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct CommonContact {
avatarImageRequest = AvatarImageRequest(imageRequest: nil, shouldAuthenticate: false)
}
}

/// A `CommonContact` that represents no-one.
public static func emptyContact(contextMailboxManager: MailboxManager) -> CommonContact {
CommonContact(recipient: Recipient(email: "", name: ""), contextMailboxManager: contextMailboxManager)
Expand Down
3 changes: 2 additions & 1 deletion MailCore/Models/Draft.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ public extension Draft {
return displayExternalRecipientState(mailboxManager: mailboxManager, recipientsList: recipientsList)
}

func displayExternalRecipientState(mailboxManager: MailboxManager, recipientsList: List<Recipient>) -> DisplayExternalRecipientStatus.State {
func displayExternalRecipientState(mailboxManager: MailboxManager,
recipientsList: List<Recipient>) -> DisplayExternalRecipientStatus.State {
let externalDisplayStatus = DisplayExternalRecipientStatus(mailboxManager: mailboxManager, recipientsList: recipientsList)
return externalDisplayStatus.state
}
Expand Down
5 changes: 2 additions & 3 deletions MailCore/Models/EditedDraft.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public struct EditedDraft: Identifiable {

public let draft: Draft
public let messageReply: MessageReply?



public static func new() -> EditedDraft {
return EditedDraft(draft: Draft(localUUID: UUID().uuidString), messageReply: nil)
}

public static func existing(draft: Draft) -> EditedDraft {
return EditedDraft(draft: draft, messageReply: nil)
}
Expand Down
4 changes: 2 additions & 2 deletions MailCore/Models/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public extension String {
/// - Parameter input: an input string
/// - Returns: The output string truncated if needed
static func truncatedForRealmIfNeeded(_ input: String) -> String {
if input.utf8.count > Self.closeToMaxRealmSize {
let index = input.index(input.startIndex, offsetBy: Self.closeToMaxRealmSize)
if input.utf8.count > closeToMaxRealmSize {
let index = input.index(input.startIndex, offsetBy: closeToMaxRealmSize)
let truncatedValue = String(input[...index]) + " [truncated]"
return truncatedValue
} else {
Expand Down
3 changes: 2 additions & 1 deletion MailCore/Models/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public class Thread: Object, Decodable, Identifiable {

public extension Thread {
/// Compute if the thread has external recipients
func displayExternalRecipientState(mailboxManager: MailboxManager, recipientsList: List<Recipient>) -> DisplayExternalRecipientStatus.State {
func displayExternalRecipientState(mailboxManager: MailboxManager,
recipientsList: List<Recipient>) -> DisplayExternalRecipientStatus.State {
let externalDisplayStatus = DisplayExternalRecipientStatus(mailboxManager: mailboxManager, recipientsList: recipientsList)
return externalDisplayStatus.state
}
Expand Down
Loading
Loading