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:
- 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

View File

@ -31,14 +31,17 @@ struct IdentifiableString: Identifiable, Equatable {
var string: String
}
struct EditableTextList<Field: View, ActionLabel: View>: View {
typealias FieldCallback = (
isNewElement: Bool,
text: Binding<String>,
onEditingChanged: (Bool) -> Void,
onCommit: () -> Void
)
struct EditableTextFieldCallback {
let isNewElement: Bool
let text: Binding<String>
let onEditingChanged: (Bool) -> Void
let onCommit: () -> Void
}
struct EditableTextList<Field: View, ActionLabel: View>: View {
@Binding var elements: [String]
var allowsDuplicates = true
@ -47,7 +50,7 @@ struct EditableTextList<Field: View, ActionLabel: View>: View {
var onAdd: ((Binding<String>) -> Void)?
let textField: (FieldCallback) -> Field
let textField: (EditableTextFieldCallback) -> Field
let addLabel: () -> ActionLabel
@ -91,12 +94,12 @@ struct EditableTextList<Field: View, ActionLabel: View>: 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<Field: View, ActionLabel: View>: View {
},
onCommit: addElement,
textField: {
textField((true, addedText, { _ in }, $0))
textField(.init(isNewElement: true, text: addedText, onEditingChanged: { _ in }, onCommit: $0))
},
addLabel: addLabel,
commitLabel: commitLabel

View File

@ -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)
}
}

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 {
MFMailComposeViewController.canSendMail()

View File

@ -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,

View File

@ -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

View File

@ -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."
)]

View File

@ -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")

View File

@ -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

View File

@ -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
}
}

View File

@ -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

View File

@ -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?")
}

View File

@ -122,7 +122,7 @@ public class InApp<PID: Hashable & RawRepresentable>: 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)
}

View File

@ -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
}

View File

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

View File

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

View File

@ -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
}
}