Upgrade SwiftLint to CI version (#266)

This commit is contained in:
Davide De Rosa 2023-03-19 16:10:40 +01:00 committed by GitHub
parent 4faeb85295
commit 513b38584d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 96 additions and 64 deletions

View File

@ -1,9 +1,15 @@
included: included:
- Passepartout - Passepartout
- PassepartoutLibrary/Sources
- PassepartoutLibrary/Tests
analyzer_rules:
- unused_declaration
- unused_import
disabled_rules: disabled_rules:
- cyclomatic_complexity - cyclomatic_complexity
- file_length - file_length
- force_cast - force_cast
- function_body_length
- identifier_name - identifier_name
- line_length - line_length
- nesting - nesting

View File

@ -31,14 +31,17 @@ struct IdentifiableString: Identifiable, Equatable {
var string: String var string: String
} }
struct EditableTextList<Field: View, ActionLabel: View>: View { struct EditableTextFieldCallback {
typealias FieldCallback = ( let isNewElement: Bool
isNewElement: Bool,
text: Binding<String>,
onEditingChanged: (Bool) -> Void,
onCommit: () -> Void
)
let text: Binding<String>
let onEditingChanged: (Bool) -> Void
let onCommit: () -> Void
}
struct EditableTextList<Field: View, ActionLabel: View>: View {
@Binding var elements: [String] @Binding var elements: [String]
var allowsDuplicates = true var allowsDuplicates = true
@ -47,7 +50,7 @@ struct EditableTextList<Field: View, ActionLabel: View>: View {
var onAdd: ((Binding<String>) -> Void)? var onAdd: ((Binding<String>) -> Void)?
let textField: (FieldCallback) -> Field let textField: (EditableTextFieldCallback) -> Field
let addLabel: () -> ActionLabel let addLabel: () -> ActionLabel
@ -91,12 +94,12 @@ struct EditableTextList<Field: View, ActionLabel: View>: View {
private func existingRow(_ element: IdentifiableString) -> some View { private func existingRow(_ element: IdentifiableString) -> some View {
let editedText = binding(toEditedElement: element) let editedText = binding(toEditedElement: element)
return textField((false, editedText, { return textField(.init(isNewElement: false, text: editedText, onEditingChanged: {
if $0 { if $0 {
editedTextStrings.removeValue(forKey: element.id) editedTextStrings.removeValue(forKey: element.id)
// print(">>> editing: '\(text.wrappedValue.string)' (\(text.wrappedValue.id))") // print(">>> editing: '\(text.wrappedValue.string)' (\(text.wrappedValue.id))")
} }
}, { }, onCommit: {
replaceElement(at: element.id, with: editedText) replaceElement(at: element.id, with: editedText)
})) }))
} }
@ -109,7 +112,7 @@ struct EditableTextList<Field: View, ActionLabel: View>: View {
}, },
onCommit: addElement, onCommit: addElement,
textField: { textField: {
textField((true, addedText, { _ in }, $0)) textField(.init(isNewElement: true, text: addedText, onEditingChanged: { _ in }, onCommit: $0))
}, },
addLabel: addLabel, addLabel: addLabel,
commitLabel: commitLabel commitLabel: commitLabel

View File

@ -26,9 +26,30 @@
import SwiftUI import SwiftUI
struct GenericCreditsView: View { 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" var licensesHeader: String? = "Licenses"
@ -60,13 +81,13 @@ struct GenericCreditsView: View {
private var sortedLicenses: [License] { private var sortedLicenses: [License] {
licenses.sorted { licenses.sorted {
$0.0.lowercased() < $1.0.lowercased() $0.name.lowercased() < $1.name.lowercased()
} }
} }
private var sortedNotices: [Notice] { private var sortedNotices: [Notice] {
notices.sorted { notices.sorted {
$0.0.lowercased() < $1.0.lowercased() $0.name.lowercased() < $1.name.lowercased()
} }
} }
@ -80,17 +101,17 @@ struct GenericCreditsView: View {
Section( Section(
header: licensesHeader.map(Text.init) header: licensesHeader.map(Text.init)
) { ) {
ForEach(sortedLicenses, id: \.0) { license in ForEach(sortedLicenses, id: \.name) { license in
NavigationLink { NavigationLink {
LicenseView( LicenseView(
url: license.2, url: license.licenseURL,
content: $contentForLicense[license.0] content: $contentForLicense[license.name]
).navigationTitle(license.0) ).navigationTitle(license.name)
} label: { } label: {
HStack { HStack {
Text(license.0) Text(license.name)
Spacer() Spacer()
Text(license.1) Text(license.licenseName)
} }
} }
} }
@ -101,8 +122,8 @@ struct GenericCreditsView: View {
Section( Section(
header: noticesHeader.map(Text.init) header: noticesHeader.map(Text.init)
) { ) {
ForEach(sortedNotices, id: \.0) { notice in ForEach(sortedNotices, id: \.name) { notice in
NavigationLink(notice.0, destination: noticeView(notice)) 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 { VStack {
Text(content.1) Text(content.noticeString)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.padding() .padding()
}.navigationTitle(content.0) }.navigationTitle(content.name)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
} }
} }

View File

@ -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 { static func canSendMail() -> Bool {
MFMailComposeViewController.canSendMail() MFMailComposeViewController.canSendMail()

View File

@ -50,7 +50,7 @@ extension OnDemandView {
.sorted { $0.string.lowercased() < $1.string.lowercased() } .sorted { $0.string.lowercased() < $1.string.lowercased() }
} }
private func ssidRow(callback: EditableTextList.FieldCallback) -> some View { private func ssidRow(callback: EditableTextFieldCallback) -> some View {
Group { Group {
if callback.isNewElement { if callback.isNewElement {
ssidField(callback: callback) 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( TextField(
Unlocalized.Network.ssid, Unlocalized.Network.ssid,
text: callback.text, text: callback.text,

View File

@ -69,10 +69,10 @@ struct ReportIssueView: View {
let logContent = logURL.trailingContent(bytes: Unlocalized.Issues.maxLogBytes) let logContent = logURL.trailingContent(bytes: Unlocalized.Issues.maxLogBytes)
let attachment = DebugLog(content: logContent).decoratedData() let attachment = DebugLog(content: logContent).decoratedData()
attachments.append(( attachments.append(.init(
attachment, data: attachment,
Unlocalized.Issues.MIME.debugLog, mimeType: Unlocalized.Issues.MIME.debugLog,
Unlocalized.Issues.Filenames.debugLog fileName: Unlocalized.Issues.Filenames.debugLog
)) ))
} }
self.attachments = attachments self.attachments = attachments

View File

@ -147,48 +147,44 @@ enum Unlocalized {
} }
enum Credits { enum Credits {
typealias License = (String, String, URL)
typealias Notice = (String, String)
static let author = "Davide De Rosa" static let author = "Davide De Rosa"
static let licenses: [License] = [( static let licenses: [GenericCreditsView.License] = [.init(
"Kvitto", "Kvitto",
"BSD", "BSD",
URL(string: "https://raw.githubusercontent.com/Cocoanetics/Kvitto/develop/LICENSE")! URL(string: "https://raw.githubusercontent.com/Cocoanetics/Kvitto/develop/LICENSE")!
), ( ), .init(
"lzo", "lzo",
"GPLv2", "GPLv2",
URL(string: "https://www.gnu.org/licenses/gpl-2.0.txt")! URL(string: "https://www.gnu.org/licenses/gpl-2.0.txt")!
), ( ), .init(
"OpenSSL", "OpenSSL",
"OpenSSL", "OpenSSL",
URL(string: "https://raw.githubusercontent.com/openssl/openssl/master/LICENSE.txt")! URL(string: "https://raw.githubusercontent.com/openssl/openssl/master/LICENSE.txt")!
), ( ), .init(
"PIATunnel", "PIATunnel",
"MIT", "MIT",
URL(string: "https://raw.githubusercontent.com/pia-foss/tunnel-apple/master/LICENSE")! URL(string: "https://raw.githubusercontent.com/pia-foss/tunnel-apple/master/LICENSE")!
), ( ), .init(
"SwiftGen", "SwiftGen",
"MIT", "MIT",
URL(string: "https://raw.githubusercontent.com/SwiftGen/SwiftGen/master/LICENCE")! URL(string: "https://raw.githubusercontent.com/SwiftGen/SwiftGen/master/LICENCE")!
), ( ), .init(
"SwiftyBeaver", "SwiftyBeaver",
"MIT", "MIT",
URL(string: "https://raw.githubusercontent.com/SwiftyBeaver/SwiftyBeaver/master/LICENSE")! URL(string: "https://raw.githubusercontent.com/SwiftyBeaver/SwiftyBeaver/master/LICENSE")!
)] )]
static let notices: [Notice] = [( static let notices: [GenericCreditsView.Notice] = [.init(
"Circle Icons", "Circle Icons",
"The logo is taken from the awesome Circle Icons set by Nick Roach." "The logo is taken from the awesome Circle Icons set by Nick Roach."
), ( ), .init(
"Country flags", "Country flags",
"The country flags are taken from: https://github.com/lipis/flag-icon-css/" "The country flags are taken from: https://github.com/lipis/flag-icon-css/"
), ( ), .init(
"OpenVPN", "OpenVPN",
"© Copyright 2022 OpenVPN | OpenVPN is a registered trademark of OpenVPN, Inc." "© Copyright 2022 OpenVPN | OpenVPN is a registered trademark of OpenVPN, Inc."
), ( ), .init(
"WireGuard", "WireGuard",
"© Copyright 2015-2022 Jason A. Donenfeld. All Rights Reserved. \"WireGuard\" and the \"WireGuard\" logo are registered trademarks of Jason A. Donenfeld." "© Copyright 2015-2022 Jason A. Donenfeld. All Rights Reserved. \"WireGuard\" and the \"WireGuard\" logo are registered trademarks of Jason A. Donenfeld."
)] )]

View File

@ -79,9 +79,9 @@ extension Profile {
extension Profile.Host: ProfileSubtype { extension Profile.Host: ProfileSubtype {
public var vpnProtocols: [VPNProtocolType] { public var vpnProtocols: [VPNProtocolType] {
if let _ = ovpnSettings { if ovpnSettings != nil {
return [.openVPN] return [.openVPN]
} else if let _ = wgSettings { } else if wgSettings != nil {
return [.wireGuard] return [.wireGuard]
} else { } else {
assertionFailure("No VPN settings found") assertionFailure("No VPN settings found")

View File

@ -96,7 +96,7 @@ public final class ProfileManager: ObservableObject {
keychainLabel: @escaping (String, VPNProtocolType) -> String, keychainLabel: @escaping (String, VPNProtocolType) -> String,
strategy: ProfileManagerStrategy strategy: ProfileManagerStrategy
) { ) {
guard let _ = UserDefaults(suiteName: appGroup) else { guard UserDefaults(suiteName: appGroup) != nil else {
fatalError("No entitlements for group '\(appGroup)'") fatalError("No entitlements for group '\(appGroup)'")
} }
self.store = store self.store = store

View File

@ -122,7 +122,7 @@ public class InApp<PID: Hashable & RawRepresentable>: NSObject,
} }
public func request(_ request: SKRequest, didFailWithError error: Error) { public func request(_ request: SKRequest, didFailWithError error: Error) {
if let _ = request as? SKProductsRequest { if request as? SKProductsRequest != nil {
DispatchQueue.main.async { DispatchQueue.main.async {
self.productFailureObserver?(error) self.productFailureObserver?(error)
} }

View File

@ -26,17 +26,17 @@
import Foundation import Foundation
public protocol DTOMapper { 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 { public protocol ModelMapper {
associatedtype DTO associatedtype DTOEntity
associatedtype Model associatedtype Model
static func toModel(_ dto: DTO) throws -> Model static func toModel(_ dto: DTOEntity) throws -> Model
} }

View File

@ -26,7 +26,7 @@
import Foundation import Foundation
public protocol StrippableContent { public protocol StrippableContent {
associatedtype T associatedtype ContentType
var stripped: T { get } var stripped: ContentType { get }
} }

View File

@ -26,7 +26,7 @@
import Foundation import Foundation
public protocol ValueHolder { public protocol ValueHolder {
associatedtype T associatedtype ValueType
var value: T { get } var value: ValueType { get }
} }