diff --git a/.swiftlint.yml b/.swiftlint.yml index 8377b8ff..5edb94ee 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,9 +1,15 @@ included: - Passepartout + - PassepartoutLibrary/Sources + - PassepartoutLibrary/Tests +analyzer_rules: + - unused_declaration + - unused_import disabled_rules: - cyclomatic_complexity - file_length - force_cast + - function_body_length - identifier_name - line_length - nesting diff --git a/Passepartout/App/Reusable/EditableTextList.swift b/Passepartout/App/Reusable/EditableTextList.swift index 3277e2fa..2de20f09 100644 --- a/Passepartout/App/Reusable/EditableTextList.swift +++ b/Passepartout/App/Reusable/EditableTextList.swift @@ -31,14 +31,17 @@ struct IdentifiableString: Identifiable, Equatable { var string: String } -struct EditableTextList: View { - typealias FieldCallback = ( - isNewElement: Bool, - text: Binding, - onEditingChanged: (Bool) -> Void, - onCommit: () -> Void - ) +struct EditableTextFieldCallback { + let isNewElement: Bool + let text: Binding + + let onEditingChanged: (Bool) -> Void + + let onCommit: () -> Void +} + +struct EditableTextList: View { @Binding var elements: [String] var allowsDuplicates = true @@ -47,7 +50,7 @@ struct EditableTextList: View { var onAdd: ((Binding) -> Void)? - let textField: (FieldCallback) -> Field + let textField: (EditableTextFieldCallback) -> Field let addLabel: () -> ActionLabel @@ -91,12 +94,12 @@ struct EditableTextList: View { private func existingRow(_ element: IdentifiableString) -> some View { let editedText = binding(toEditedElement: element) - return textField((false, editedText, { + return textField(.init(isNewElement: false, text: editedText, onEditingChanged: { if $0 { editedTextStrings.removeValue(forKey: element.id) // print(">>> editing: '\(text.wrappedValue.string)' (\(text.wrappedValue.id))") } - }, { + }, onCommit: { replaceElement(at: element.id, with: editedText) })) } @@ -109,7 +112,7 @@ struct EditableTextList: View { }, onCommit: addElement, textField: { - textField((true, addedText, { _ in }, $0)) + textField(.init(isNewElement: true, text: addedText, onEditingChanged: { _ in }, onCommit: $0)) }, addLabel: addLabel, commitLabel: commitLabel diff --git a/Passepartout/App/Reusable/GenericCreditsView.swift b/Passepartout/App/Reusable/GenericCreditsView.swift index 043b72b3..edcfe41e 100644 --- a/Passepartout/App/Reusable/GenericCreditsView.swift +++ b/Passepartout/App/Reusable/GenericCreditsView.swift @@ -26,9 +26,30 @@ import SwiftUI struct GenericCreditsView: View { - typealias License = (String, String, URL) + struct License { + let name: String - typealias Notice = (String, String) + let licenseName: String + + let licenseURL: URL + + init(_ name: String, _ licenseName: String, _ licenseURL: URL) { + self.name = name + self.licenseName = licenseName + self.licenseURL = licenseURL + } + } + + struct Notice { + let name: String + + let noticeString: String + + init(_ name: String, _ noticeString: String) { + self.name = name + self.noticeString = noticeString + } + } var licensesHeader: String? = "Licenses" @@ -60,13 +81,13 @@ struct GenericCreditsView: View { private var sortedLicenses: [License] { licenses.sorted { - $0.0.lowercased() < $1.0.lowercased() + $0.name.lowercased() < $1.name.lowercased() } } private var sortedNotices: [Notice] { notices.sorted { - $0.0.lowercased() < $1.0.lowercased() + $0.name.lowercased() < $1.name.lowercased() } } @@ -80,17 +101,17 @@ struct GenericCreditsView: View { Section( header: licensesHeader.map(Text.init) ) { - ForEach(sortedLicenses, id: \.0) { license in + ForEach(sortedLicenses, id: \.name) { license in NavigationLink { LicenseView( - url: license.2, - content: $contentForLicense[license.0] - ).navigationTitle(license.0) + url: license.licenseURL, + content: $contentForLicense[license.name] + ).navigationTitle(license.name) } label: { HStack { - Text(license.0) + Text(license.name) Spacer() - Text(license.1) + Text(license.licenseName) } } } @@ -101,8 +122,8 @@ struct GenericCreditsView: View { Section( header: noticesHeader.map(Text.init) ) { - ForEach(sortedNotices, id: \.0) { notice in - NavigationLink(notice.0, destination: noticeView(notice)) + ForEach(sortedNotices, id: \.name) { notice in + NavigationLink(notice.name, destination: noticeView(notice)) } } } @@ -124,12 +145,12 @@ struct GenericCreditsView: View { } } - private func noticeView(_ content: (String, String)) -> some View { + private func noticeView(_ content: Notice) -> some View { VStack { - Text(content.1) + Text(content.noticeString) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .padding() - }.navigationTitle(content.0) + }.navigationTitle(content.name) .navigationBarTitleDisplayMode(.inline) } } diff --git a/Passepartout/App/Reusable/MailComposerView.swift b/Passepartout/App/Reusable/MailComposerView.swift index 654ce91b..69602167 100644 --- a/Passepartout/App/Reusable/MailComposerView.swift +++ b/Passepartout/App/Reusable/MailComposerView.swift @@ -39,7 +39,13 @@ struct MailComposerView: UIViewControllerRepresentable { } } - typealias Attachment = (data: Data, mimeType: String, fileName: String) + struct Attachment { + let data: Data + + let mimeType: String + + let fileName: String + } static func canSendMail() -> Bool { MFMailComposeViewController.canSendMail() diff --git a/Passepartout/App/Views/OnDemandView+SSID.swift b/Passepartout/App/Views/OnDemandView+SSID.swift index a9ea0ce8..2b72d893 100644 --- a/Passepartout/App/Views/OnDemandView+SSID.swift +++ b/Passepartout/App/Views/OnDemandView+SSID.swift @@ -50,7 +50,7 @@ extension OnDemandView { .sorted { $0.string.lowercased() < $1.string.lowercased() } } - private func ssidRow(callback: EditableTextList.FieldCallback) -> some View { + private func ssidRow(callback: EditableTextFieldCallback) -> some View { Group { if callback.isNewElement { ssidField(callback: callback) @@ -62,7 +62,7 @@ extension OnDemandView { } } - private func ssidField(callback: EditableTextList.FieldCallback) -> some View { + private func ssidField(callback: EditableTextFieldCallback) -> some View { TextField( Unlocalized.Network.ssid, text: callback.text, diff --git a/Passepartout/App/Views/ReportIssueView.swift b/Passepartout/App/Views/ReportIssueView.swift index 9cc28d9a..83f1453d 100644 --- a/Passepartout/App/Views/ReportIssueView.swift +++ b/Passepartout/App/Views/ReportIssueView.swift @@ -69,10 +69,10 @@ struct ReportIssueView: View { let logContent = logURL.trailingContent(bytes: Unlocalized.Issues.maxLogBytes) let attachment = DebugLog(content: logContent).decoratedData() - attachments.append(( - attachment, - Unlocalized.Issues.MIME.debugLog, - Unlocalized.Issues.Filenames.debugLog + attachments.append(.init( + data: attachment, + mimeType: Unlocalized.Issues.MIME.debugLog, + fileName: Unlocalized.Issues.Filenames.debugLog )) } self.attachments = attachments diff --git a/Passepartout/AppShared/L10n/Unlocalized.swift b/Passepartout/AppShared/L10n/Unlocalized.swift index 2746da4f..afc4d72e 100644 --- a/Passepartout/AppShared/L10n/Unlocalized.swift +++ b/Passepartout/AppShared/L10n/Unlocalized.swift @@ -147,48 +147,44 @@ enum Unlocalized { } enum Credits { - typealias License = (String, String, URL) - - typealias Notice = (String, String) - static let author = "Davide De Rosa" - static let licenses: [License] = [( + static let licenses: [GenericCreditsView.License] = [.init( "Kvitto", "BSD", URL(string: "https://raw.githubusercontent.com/Cocoanetics/Kvitto/develop/LICENSE")! - ), ( + ), .init( "lzo", "GPLv2", URL(string: "https://www.gnu.org/licenses/gpl-2.0.txt")! - ), ( + ), .init( "OpenSSL", "OpenSSL", URL(string: "https://raw.githubusercontent.com/openssl/openssl/master/LICENSE.txt")! - ), ( + ), .init( "PIATunnel", "MIT", URL(string: "https://raw.githubusercontent.com/pia-foss/tunnel-apple/master/LICENSE")! - ), ( + ), .init( "SwiftGen", "MIT", URL(string: "https://raw.githubusercontent.com/SwiftGen/SwiftGen/master/LICENCE")! - ), ( + ), .init( "SwiftyBeaver", "MIT", URL(string: "https://raw.githubusercontent.com/SwiftyBeaver/SwiftyBeaver/master/LICENSE")! )] - static let notices: [Notice] = [( + static let notices: [GenericCreditsView.Notice] = [.init( "Circle Icons", "The logo is taken from the awesome Circle Icons set by Nick Roach." - ), ( + ), .init( "Country flags", "The country flags are taken from: https://github.com/lipis/flag-icon-css/" - ), ( + ), .init( "OpenVPN", "© Copyright 2022 OpenVPN | OpenVPN is a registered trademark of OpenVPN, Inc." - ), ( + ), .init( "WireGuard", "© Copyright 2015-2022 Jason A. Donenfeld. All Rights Reserved. \"WireGuard\" and the \"WireGuard\" logo are registered trademarks of Jason A. Donenfeld." )] diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Host+Extensions.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Host+Extensions.swift index 10a7d8aa..a4c2a0e2 100644 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Host+Extensions.swift +++ b/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Host+Extensions.swift @@ -79,9 +79,9 @@ extension Profile { extension Profile.Host: ProfileSubtype { public var vpnProtocols: [VPNProtocolType] { - if let _ = ovpnSettings { + if ovpnSettings != nil { return [.openVPN] - } else if let _ = wgSettings { + } else if wgSettings != nil { return [.wireGuard] } else { assertionFailure("No VPN settings found") diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Models/Profile+Header.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Models/Profile+Header.swift index d5ce91a2..3987a965 100644 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Models/Profile+Header.swift +++ b/PassepartoutLibrary/Sources/PassepartoutCore/Models/Profile+Header.swift @@ -49,7 +49,7 @@ extension Profile { // MARK: Hashable - public static func ==(lhs: Self, rhs: Self) -> Bool { + public static func == (lhs: Self, rhs: Self) -> Bool { lhs.uuid == rhs.uuid && lhs.name == rhs.name && lhs.providerName == rhs.providerName diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/PassepartoutError.swift b/PassepartoutLibrary/Sources/PassepartoutCore/PassepartoutError.swift index 9e37f661..79f0d982 100644 --- a/PassepartoutLibrary/Sources/PassepartoutCore/PassepartoutError.swift +++ b/PassepartoutLibrary/Sources/PassepartoutCore/PassepartoutError.swift @@ -32,7 +32,7 @@ public struct PassepartoutError: Error, Equatable { self.string = string } - public static func ==(lhs: Self, rhs: Self) -> Bool { + public static func == (lhs: Self, rhs: Self) -> Bool { lhs.string == rhs.string } } diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift index 25cf1961..fa8c993a 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift @@ -96,7 +96,7 @@ public final class ProfileManager: ObservableObject { keychainLabel: @escaping (String, VPNProtocolType) -> String, strategy: ProfileManagerStrategy ) { - guard let _ = UserDefaults(suiteName: appGroup) else { + guard UserDefaults(suiteName: appGroup) != nil else { fatalError("No entitlements for group '\(appGroup)'") } self.store = store diff --git a/PassepartoutLibrary/Sources/PassepartoutProviders/Repositories/ServerMapper.swift b/PassepartoutLibrary/Sources/PassepartoutProviders/Repositories/ServerMapper.swift index 4a1216fd..b77f67ca 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProviders/Repositories/ServerMapper.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProviders/Repositories/ServerMapper.swift @@ -180,7 +180,7 @@ private extension CDInfrastructureServer { } extension CDInfrastructurePreset: Comparable { - public static func <(lhs: CDInfrastructurePreset, rhs: CDInfrastructurePreset) -> Bool { + public static func < (lhs: CDInfrastructurePreset, rhs: CDInfrastructurePreset) -> Bool { guard let lname = lhs.name, let rname = rhs.name else { fatalError("CDPreset has no name?") } diff --git a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/InApp.swift b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/InApp.swift index 73400e23..294f77a9 100644 --- a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/InApp.swift +++ b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/InApp.swift @@ -122,7 +122,7 @@ public class InApp: NSObject, } public func request(_ request: SKRequest, didFailWithError error: Error) { - if let _ = request as? SKProductsRequest { + if request as? SKProductsRequest != nil { DispatchQueue.main.async { self.productFailureObserver?(error) } diff --git a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/Mapper.swift b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/Mapper.swift index fba97877..381691d2 100644 --- a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/Mapper.swift +++ b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/Mapper.swift @@ -26,17 +26,17 @@ import Foundation public protocol DTOMapper { - associatedtype WS + associatedtype WSEntity - associatedtype DTO + associatedtype DTOEntity - func toDTO(_ ws: WS) throws -> DTO + func toDTO(_ ws: WSEntity) throws -> DTOEntity } public protocol ModelMapper { - associatedtype DTO + associatedtype DTOEntity associatedtype Model - static func toModel(_ dto: DTO) throws -> Model + static func toModel(_ dto: DTOEntity) throws -> Model } diff --git a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/StrippableContent.swift b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/StrippableContent.swift index 28d15d92..a1fb055d 100644 --- a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/StrippableContent.swift +++ b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/StrippableContent.swift @@ -26,7 +26,7 @@ import Foundation public protocol StrippableContent { - associatedtype T + associatedtype ContentType - var stripped: T { get } + var stripped: ContentType { get } } diff --git a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/ValueHolder.swift b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/ValueHolder.swift index 6d3df89d..205a29e9 100644 --- a/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/ValueHolder.swift +++ b/PassepartoutLibrary/Sources/PassepartoutUtils/Reusable/ValueHolder.swift @@ -26,7 +26,7 @@ import Foundation public protocol ValueHolder { - associatedtype T + associatedtype ValueType - var value: T { get } + var value: ValueType { get } } diff --git a/PassepartoutLibrary/Sources/PassepartoutVPN/Extensions/VPNProtocolType+Extensions.swift b/PassepartoutLibrary/Sources/PassepartoutVPN/Extensions/VPNProtocolType+Extensions.swift index 7766e471..c8dc0375 100644 --- a/PassepartoutLibrary/Sources/PassepartoutVPN/Extensions/VPNProtocolType+Extensions.swift +++ b/PassepartoutLibrary/Sources/PassepartoutVPN/Extensions/VPNProtocolType+Extensions.swift @@ -29,7 +29,7 @@ import TunnelKitWireGuard import PassepartoutCore extension VPNProtocolType: Comparable { - public static func <(lhs: Self, rhs: Self) -> Bool { + public static func < (lhs: Self, rhs: Self) -> Bool { lhs.description < rhs.description } }