Fine-tune SwiftLint (#265)

This commit is contained in:
Davide De Rosa 2023-03-19 14:41:53 +01:00 committed by GitHub
parent 1dda8dce98
commit fbd32d8b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 107 additions and 47 deletions

10
.swiftlint.yml Normal file
View File

@ -0,0 +1,10 @@
included:
- Passepartout
disabled_rules:
- cyclomatic_complexity
- file_length
- force_cast
- identifier_name
- line_length
- nesting
- todo

View File

@ -32,8 +32,9 @@ CFG_MAC_ID = com.algoritmico.ios.PassepartoutMac
CFG_LAUNCHER_ID = com.algoritmico.ios.PassepartoutLauncher
CFG_GROUP_ID = com.algoritmico.Passepartout
CFG_APPSTORE_ID = 1433648537
CFG_COPYRIGHT = Copyright © 2022 Davide De Rosa. All rights reserved.
CFG_COPYRIGHT = Copyright © 2023 Davide De Rosa. All rights reserved.
PATH = $(PATH):/opt/homebrew/bin:/usr/local/bin:/usr/local/go/bin
CUSTOM_SCRIPT_PATH = $(PATH)
#include? "Secret.xcconfig"

View File

@ -1314,7 +1314,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "PATH=$CUSTOM_SCRIPT_PATH\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
0EADDC7227F0677F0093E303 /* Copy Core Data codegen */ = {
isa = PBXShellScriptBuildPhase;

View File

@ -418,15 +418,9 @@ extension View {
}
func themeSaveButtonLabel() -> some View {
// themeCheckmarkImage.asSystemImage
Text(L10n.Global.Strings.save)
}
// func themeDoneButtonLabel() -> some View {
//// themeCheckmarkImage.asSystemImage
// Text(L10n.Global.Strings.ok)
// }
func themeTextPicker<T: Hashable>(_ title: String, selection: Binding<T>, values: [T], description: @escaping (T) -> String) -> some View {
StyledPicker(title: title, selection: selection, values: values) {
Text(description($0))

View File

@ -31,11 +31,11 @@ extension ProviderMetadata: Identifiable, Comparable, Hashable {
name
}
public static func ==(lhs: Self, rhs: Self) -> Bool {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.name == rhs.name
}
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.fullName.lowercased() < rhs.fullName.lowercased()
}
@ -45,32 +45,32 @@ extension ProviderMetadata: Identifiable, Comparable, Hashable {
}
extension ProviderCategory: Comparable {
public static func ==(lhs: Self, rhs: Self) -> Bool {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.name.lowercased() == rhs.name.lowercased()
}
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.name.lowercased() < rhs.name.lowercased()
}
}
extension ProviderLocation: Comparable {
public static func ==(lhs: Self, rhs: Self) -> Bool {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.countryCode == rhs.countryCode
}
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.localizedCountry < rhs.localizedCountry
}
}
extension ProviderServer: Comparable {
public static func ==(lhs: Self, rhs: Self) -> Bool {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.id == rhs.id
}
// "Default" comes first (nil localizedName)
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
guard lhs.localizedName != rhs.localizedName else {
guard let li = lhs.serverIndex else {
return true
@ -97,11 +97,11 @@ extension ProviderServer: Comparable {
}
extension ProviderServer.Preset: Comparable {
public static func ==(lhs: Self, rhs: Self) -> Bool {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.name == rhs.name
}
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.name < rhs.name
}
}

View File

@ -25,7 +25,7 @@
import SwiftUI
func ??<T>(lhs: Binding<T?>, rhs: T) -> Binding<T> {
func ?? <T>(lhs: Binding<T?>, rhs: T) -> Binding<T> {
Binding {
lhs.wrappedValue ?? rhs
} set: {

View File

@ -192,9 +192,9 @@ extension EditableTextList {
commit()
}
private func onMove(indexSet: IndexSet, to: Int) {
private func onMove(indexSet: IndexSet, to offset: Int) {
var mapped = mapping(identifiableElements)
mapped.move(fromOffsets: indexSet, toOffset: to)
mapped.move(fromOffsets: indexSet, toOffset: offset)
identifiableElements = mapped
commit()
}

View File

@ -37,11 +37,11 @@ struct Shortcut: Identifiable, Hashable, Comparable {
native.identifier
}
static func ==(lhs: Self, rhs: Self) -> Bool {
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.phrase == rhs.phrase
}
static func <(lhs: Self, rhs: Self) -> Bool {
static func < (lhs: Self, rhs: Self) -> Bool {
lhs.phrase < rhs.phrase
}

View File

@ -39,7 +39,7 @@ struct Validators {
}
static func notNil(_ string: String?) throws {
guard let _ = string else {
guard string != nil else {
throw ValidationError.notSet
}
}
@ -73,7 +73,7 @@ struct Validators {
}
static func url(_ string: String) throws {
guard let _ = URL(string: string) else {
guard URL(string: string) != nil else {
throw ValidationError.url
}
}

View File

@ -143,7 +143,7 @@ struct AddProviderView: View {
}
private func onErrorMessage(_ message: String?, _ scrollProxy: ScrollViewProxy) {
guard let _ = message else {
guard message != nil else {
return
}
scrollToErrorMessage(scrollProxy)

View File

@ -320,40 +320,89 @@ extension EndpointAdvancedView.OpenVPNView {
}
}
extension OpenVPN.Configuration {
var communicationSettings: (cipher: OpenVPN.Cipher?, digest: OpenVPN.Digest?, xor: OpenVPN.XORMethod?)? {
private extension OpenVPN.Configuration {
struct CommunicationOptions {
let cipher: OpenVPN.Cipher?
let digest: OpenVPN.Digest?
let xor: OpenVPN.XORMethod?
}
struct CompressionOptions {
let framing: OpenVPN.CompressionFraming?
let algorithm: OpenVPN.CompressionAlgorithm?
}
struct DNSOptions {
let servers: [String]
let domains: [String]
}
struct ProxyOptions {
let proxy: Proxy?
let pac: URL?
let bypass: [String]
}
struct OtherOptions {
let keepAlive: TimeInterval?
let reneg: TimeInterval?
let randomizeEndpoint: Bool?
let randomizeHostnames: Bool?
}
var communicationSettings: CommunicationOptions? {
guard cipher != nil || digest != nil || xorMethod != nil else {
return nil
}
return (cipher, digest, xorMethod)
return .init(cipher: cipher, digest: digest, xor: xorMethod)
}
var compressionSettings: (framing: OpenVPN.CompressionFraming?, algorithm: OpenVPN.CompressionAlgorithm?)? {
var compressionSettings: CompressionOptions? {
guard compressionFraming != nil || compressionAlgorithm != nil else {
return nil
}
return (compressionFraming, compressionAlgorithm)
return .init(framing: compressionFraming, algorithm: compressionAlgorithm)
}
var dnsSettings: (servers: [String], domains: [String])? {
var dnsSettings: DNSOptions? {
guard !(dnsServers?.isEmpty ?? true) || !(searchDomains?.isEmpty ?? true) else {
return nil
}
return (dnsServers ?? [], searchDomains ?? [])
return .init(servers: dnsServers ?? [], domains: searchDomains ?? [])
}
var proxySettings: (proxy: Proxy?, pac: URL?, bypass: [String])? {
guard httpsProxy != nil || httpProxy != nil || proxyAutoConfigurationURL != nil || !(proxyBypassDomains?.isEmpty ?? true) else {
var proxySettings: ProxyOptions? {
guard httpsProxy != nil || httpProxy != nil ||
proxyAutoConfigurationURL != nil || !(proxyBypassDomains?.isEmpty ?? true) else {
return nil
}
return (httpsProxy ?? httpProxy, proxyAutoConfigurationURL, proxyBypassDomains ?? [])
return .init(
proxy: httpsProxy ?? httpProxy,
pac: proxyAutoConfigurationURL,
bypass: proxyBypassDomains ?? []
)
}
var otherSettings: (keepAlive: TimeInterval?, reneg: TimeInterval?, randomizeEndpoint: Bool?, randomizeHostnames: Bool?)? {
guard keepAliveInterval != nil || renegotiatesAfter != nil || randomizeEndpoint != nil || randomizeHostnames != nil else {
var otherSettings: OtherOptions? {
guard keepAliveInterval != nil || renegotiatesAfter != nil ||
randomizeEndpoint != nil || randomizeHostnames != nil else {
return nil
}
return (keepAliveInterval, renegotiatesAfter, randomizeEndpoint, randomizeHostnames)
return .init(
keepAlive: keepAliveInterval,
reneg: renegotiatesAfter,
randomizeEndpoint: randomizeEndpoint,
randomizeHostnames: randomizeHostnames
)
}
}

View File

@ -89,11 +89,17 @@ extension EndpointAdvancedView.WireGuardView {
}
}
extension WireGuard.Configuration {
var dnsSettings: (servers: [String], domains: [String])? {
private extension WireGuard.Configuration {
struct DNSOptions {
let servers: [String]
let domains: [String]
}
var dnsSettings: DNSOptions? {
guard !dnsServers.isEmpty || !dnsSearchDomains.isEmpty else {
return nil
}
return (dnsServers, dnsSearchDomains)
return .init(servers: dnsServers, domains: dnsSearchDomains)
}
}

View File

@ -111,7 +111,7 @@ extension OnDemandView.SSIDList {
} set: { newValue in
withSSIDs.forEach {
guard newValue.contains($0.key) else {
if let _ = withSSIDs[$0.key] {
if withSSIDs[$0.key] != nil {
withSSIDs[$0.key] = false
} else {
withSSIDs.removeValue(forKey: $0.key)

View File

@ -255,7 +255,7 @@ extension ProviderLocationView {
HStack {
themeAssetsCountryImage(location.countryCode).asAssetImage
VStack {
if let singleServer = location.onlyServer, let _ = singleServer.localizedShortDescription {
if let singleServer = location.onlyServer, singleServer.localizedShortDescription != nil {
Text(location.localizedCountry)
.frame(maxWidth: .infinity, alignment: .leading)
Text(singleServer.localizedShortDescription ?? "")

View File

@ -75,13 +75,13 @@ extension ObservableVPNState {
}
extension Profile: Comparable {
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.header < rhs.header
}
}
extension Profile.Header: Comparable {
public static func <(lhs: Self, rhs: Self) -> Bool {
public static func < (lhs: Self, rhs: Self) -> Bool {
lhs.name.lowercased() < rhs.name.lowercased()
}
}

View File

@ -79,7 +79,7 @@ class PassepartoutMenu {
] as [ItemGroup])
}
if let _ = profileManager.activeProfileId {
if profileManager.activeProfileId != nil {
children.append(contentsOf: [
SeparatorItem(),
VPNItemGroup(