From cfdb1edc589f18e481a6fdde2530afffdc3c1f45 Mon Sep 17 00:00:00 2001 From: Antoine van der Lee <4329185+AvdLee@users.noreply.github.com> Date: Mon, 24 Apr 2023 11:08:01 +0200 Subject: [PATCH] Clean up the project by fixing SwiftLint warnings --- .../xcschemes/Diagnostics.xcscheme | 2 +- .../project.pbxproj | 8 +++++--- .../xcschemes/Diagnostics-Example.xcscheme | 2 +- .../Diagnostics-Example/CustomFilters.swift | 2 +- .../Diagnostics-Example/CustomReporter.swift | 4 ++-- .../CustomSmartInsights.swift | 2 +- .../Supporting Files/AppDelegate.swift | 2 +- .../Diagnostics-Example/ViewController.swift | 8 ++++---- Sources/DiagnosticsReporter.swift | 4 ++-- Sources/HTMLGenerating.swift | 2 +- Sources/Logging/DiagnosticsLogger.swift | 18 +++++++++--------- Sources/Logging/Loggable.swift | 8 ++++---- .../Reporters/AppSystemMetadataReporter.swift | 8 ++++---- .../DirectoryTree/DirectoryTreeFactory.swift | 4 ++-- .../DirectoryTree/DirectoryTreeReporter.swift | 4 ++-- .../DirectoryTreeStringFactory.swift | 6 +++--- Sources/Reporters/SmartInsightsReporter.swift | 4 +--- .../SmartInsights/CellularAllowedInsight.swift | 2 +- .../SmartInsights/UpdateAvailableInsight.swift | 10 +++++----- 19 files changed, 50 insertions(+), 50 deletions(-) diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/Diagnostics.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/Diagnostics.xcscheme index 94bb3cf..5865328 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/Diagnostics.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/Diagnostics.xcscheme @@ -1,6 +1,6 @@ [SmartInsightProviding] { diff --git a/Example/Diagnostics-Example/Supporting Files/AppDelegate.swift b/Example/Diagnostics-Example/Supporting Files/AppDelegate.swift index c107bad..608f7f2 100644 --- a/Example/Diagnostics-Example/Supporting Files/AppDelegate.swift +++ b/Example/Diagnostics-Example/Supporting Files/AppDelegate.swift @@ -6,8 +6,8 @@ // Copyright © 2019 WeTransfer. All rights reserved. // // swiftlint:disable line_length -import UIKit import Diagnostics +import UIKit @UIApplicationMain final class AppDelegate: UIResponder, UIApplicationDelegate { diff --git a/Example/Diagnostics-Example/ViewController.swift b/Example/Diagnostics-Example/ViewController.swift index 1b2c05d..ca3356a 100644 --- a/Example/Diagnostics-Example/ViewController.swift +++ b/Example/Diagnostics-Example/ViewController.swift @@ -6,9 +6,9 @@ // Copyright © 2019 WeTransfer. All rights reserved. // -import UIKit -import MessageUI import Diagnostics +import MessageUI +import UIKit final class ViewController: UIViewController { @@ -19,8 +19,8 @@ final class ViewController: UIViewController { let documentsURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) let directoryTreesReporter = DirectoryTreesReporter( - directories: [ - documentsURL + trunks: [ + Directory(url: documentsURL) ] ) reporters.insert(directoryTreesReporter, at: 2) diff --git a/Sources/DiagnosticsReporter.swift b/Sources/DiagnosticsReporter.swift index a461e6b..b8d9844 100644 --- a/Sources/DiagnosticsReporter.swift +++ b/Sources/DiagnosticsReporter.swift @@ -68,10 +68,10 @@ public enum DiagnosticsReporter { .filter { ($0 is SmartInsightsReporter) == false } .map { reporter -> DiagnosticsChapter in var chapter = reporter.report() - if let filters = filters, !filters.isEmpty { + if let filters, !filters.isEmpty { chapter.applyingFilters(filters) } - if let smartInsightsProvider = smartInsightsProvider { + if let smartInsightsProvider { let insights = smartInsightsProvider.smartInsights(for: chapter) smartInsights.append(contentsOf: insights) } diff --git a/Sources/HTMLGenerating.swift b/Sources/HTMLGenerating.swift index 26fc9ae..fd70dfd 100644 --- a/Sources/HTMLGenerating.swift +++ b/Sources/HTMLGenerating.swift @@ -69,7 +69,7 @@ extension DiagnosticsChapter: HTMLGenerating { html += "
" - if let formatter = formatter { + if let formatter { html += formatter.format(diagnostics) } else { html += diagnostics.html() diff --git a/Sources/Logging/DiagnosticsLogger.swift b/Sources/Logging/DiagnosticsLogger.swift index 8908586..b5cc9f3 100644 --- a/Sources/Logging/DiagnosticsLogger.swift +++ b/Sources/Logging/DiagnosticsLogger.swift @@ -6,9 +6,9 @@ // Copyright © 2019 WeTransfer. All rights reserved. // +import ExceptionCatcher import Foundation import MetricKit -import ExceptionCatcher #if os(macOS) import AppKit @@ -23,10 +23,10 @@ public final class DiagnosticsLogger { private lazy var logFileLocation: URL = FileManager.default.documentsDirectory.appendingPathComponent("diagnostics_log.txt") - private let inputPipe: Pipe = Pipe() - private let outputPipe: Pipe = Pipe() + private let inputPipe = Pipe() + private let outputPipe = Pipe() - private let queue: DispatchQueue = DispatchQueue( + private let queue = DispatchQueue( label: "com.wetransfer.diagnostics.logger", qos: .utility, autoreleaseFrequency: .workItem, @@ -59,10 +59,10 @@ public final class DiagnosticsLogger { return ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil } - private lazy var metricsMonitor: MetricsMonitor = MetricsMonitor() + private lazy var metricsMonitor = MetricsMonitor() /// Whether the logger is setup and ready to use. - private var isSetup: Bool = false + private var isSetup = false /// Whether the logger is setup and ready to use. public static func isSetUp() -> Bool { @@ -167,12 +167,12 @@ extension DiagnosticsLogger { } queue.async { [weak self] in - guard let self = self else { return } + guard let self else { return } let coordinator = NSFileCoordinator(filePresenter: nil) var error: NSError? coordinator.coordinate(writingItemAt: self.logFileLocation, error: &error) { [weak self] url in do { - guard let self = self, self.canWriteNewLogs else { return } + guard let self, self.canWriteNewLogs else { return } guard let data = loggable.logData else { return assertionFailure("Missing file handle or invalid output logged") @@ -261,7 +261,7 @@ private extension DiagnosticsLogger { return assertionFailure("Invalid data is logged") } - string.enumerateLines(invoking: { [weak self] (line, _) in + string.enumerateLines(invoking: { [weak self] line, _ in self?.log(SystemLog(line: line)) }) } diff --git a/Sources/Logging/Loggable.swift b/Sources/Logging/Loggable.swift index abf3d3c..48ad553 100644 --- a/Sources/Logging/Loggable.swift +++ b/Sources/Logging/Loggable.swift @@ -25,7 +25,7 @@ extension Loggable { var cssClass: LoggableCSSClass? { nil } var logData: Data? { - if let cssClass = cssClass { + if let cssClass { return "

\(logMessage)

\n".data(using: .utf8) } else { return "\(message)\n".data(using: .utf8) @@ -34,11 +34,11 @@ extension Loggable { private var logMessage: String { var messages: [String] = [] - if let date = date { + if let date { let date = DateFormatter.current.string(from: date) messages.append("\(date)") } - if let prefix = prefix { + if let prefix { messages.append("\(prefix)") } messages.append("\(self.message)") @@ -79,7 +79,7 @@ struct LogItem: Loggable { case .error(let error, let description): var message = "\(error) | \(error.localizedDescription)" - if let description = description { + if let description { message += " | \(description)" } diff --git a/Sources/Reporters/AppSystemMetadataReporter.swift b/Sources/Reporters/AppSystemMetadataReporter.swift index ce52937..ec3c92a 100644 --- a/Sources/Reporters/AppSystemMetadataReporter.swift +++ b/Sources/Reporters/AppSystemMetadataReporter.swift @@ -6,8 +6,8 @@ // Copyright © 2019 WeTransfer. All rights reserved. // -import Foundation import CoreTelephony +import Foundation /// Reports App and System specific metadata like OS and App version. public struct AppSystemMetadataReporter: DiagnosticsReporting { @@ -53,9 +53,9 @@ public struct AppSystemMetadataReporter: DiagnosticsReporting { var diagnostics: [String: String] { var systemInfo = utsname() uname(&systemInfo) - var hardware = Mirror(reflecting: systemInfo.machine).children.reduce("") { identifier, element in - guard let value = element.value as? Int8, value != 0 else { return identifier } - return identifier + String(UnicodeScalar(UInt8(value))) + var hardware = Mirror(reflecting: systemInfo.machine).children.reduce(into: "") { identifier, element in + guard let value = element.value as? Int8, value != 0 else { return } + identifier += String(UnicodeScalar(UInt8(value))) } if let hardwareName = Self.hardwareName[hardware] { diff --git a/Sources/Reporters/DirectoryTree/DirectoryTreeFactory.swift b/Sources/Reporters/DirectoryTree/DirectoryTreeFactory.swift index 77999fd..5d325ee 100644 --- a/Sources/Reporters/DirectoryTree/DirectoryTreeFactory.swift +++ b/Sources/Reporters/DirectoryTree/DirectoryTreeFactory.swift @@ -25,10 +25,10 @@ struct DirectoryTreeFactory { var maxLength: Int = 10 /// Whether hidden files should be captured. - var includeHiddenFiles: Bool = false + var includeHiddenFiles = false /// Whether symbolic links should be captured. - var includeSymbolicLinks: Bool = false + var includeSymbolicLinks = false /// The file manager to use for operations. var fileManager: FileManager = .default diff --git a/Sources/Reporters/DirectoryTree/DirectoryTreeReporter.swift b/Sources/Reporters/DirectoryTree/DirectoryTreeReporter.swift index 2b87d63..ff8a510 100644 --- a/Sources/Reporters/DirectoryTree/DirectoryTreeReporter.swift +++ b/Sources/Reporters/DirectoryTree/DirectoryTreeReporter.swift @@ -15,7 +15,7 @@ public struct Directory { let includeHiddenFiles: Bool let includeSymbolicLinks: Bool let printFullPath: Bool - + /// Directory/Group to be diagnosed /// - Parameters: /// - url: location of resource @@ -75,7 +75,7 @@ public struct DirectoryTreesReporter: DiagnosticsReporting { } self.init(trunks: newTrunks) } - + public init(trunks: [Directory]) { self.trunks = trunks } diff --git a/Sources/Reporters/DirectoryTree/DirectoryTreeStringFactory.swift b/Sources/Reporters/DirectoryTree/DirectoryTreeStringFactory.swift index c8f6c86..55f9452 100644 --- a/Sources/Reporters/DirectoryTree/DirectoryTreeStringFactory.swift +++ b/Sources/Reporters/DirectoryTree/DirectoryTreeStringFactory.swift @@ -12,13 +12,13 @@ private struct DirectoryTreeStringFactory { let node: DirectoryTreeNode /// Whether the full path of the node should be printed or just the name. - var printFullPath: Bool = false + var printFullPath = false /// The indent to apply, used during recursive looping over the nodes. var indent: String = "" /// Whether this node should be handled as a last node. - var isLastNode: Bool = true + var isLastNode = true func make() -> String { let name = printFullPath ? "\(node.path)/\(node.name)" : node.name @@ -29,7 +29,7 @@ private struct DirectoryTreeStringFactory { } return currentString + contents.enumerated() - .map { (idx, content) in + .map { idx, content in let indent = "\(indent)\(isLastNode ? " " : "| ")" let isLastNode = idx == contents.count - 1 let childFactory = DirectoryTreeStringFactory( diff --git a/Sources/Reporters/SmartInsightsReporter.swift b/Sources/Reporters/SmartInsightsReporter.swift index aa1e3d3..7557733 100644 --- a/Sources/Reporters/SmartInsightsReporter.swift +++ b/Sources/Reporters/SmartInsightsReporter.swift @@ -53,10 +53,8 @@ public struct SmartInsightsReporter: DiagnosticsReporting { } public func report() -> DiagnosticsChapter { - let diagnostics: [String: String] = insights.compactMap { $0 }.reduce([:]) { metadata, insight in - var metadata = metadata + let diagnostics: [String: String] = insights.compactMap { $0 }.reduce(into: [:]) { metadata, insight in metadata[insight.name] = insight.result.message - return metadata } return DiagnosticsChapter(title: title, diagnostics: diagnostics) } diff --git a/Sources/SmartInsights/CellularAllowedInsight.swift b/Sources/SmartInsights/CellularAllowedInsight.swift index 4f798d3..3cb6655 100644 --- a/Sources/SmartInsights/CellularAllowedInsight.swift +++ b/Sources/SmartInsights/CellularAllowedInsight.swift @@ -5,8 +5,8 @@ // Created by Antoine van der Lee on 27/07/2022. // -import Foundation import CoreTelephony +import Foundation #if os(iOS) && !targetEnvironment(macCatalyst) /// Shows an insight on whether the user has enabled cellular data system-wide for this app. diff --git a/Sources/SmartInsights/UpdateAvailableInsight.swift b/Sources/SmartInsights/UpdateAvailableInsight.swift index bd36bd4..aaf6f44 100644 --- a/Sources/SmartInsights/UpdateAvailableInsight.swift +++ b/Sources/SmartInsights/UpdateAvailableInsight.swift @@ -21,7 +21,7 @@ struct UpdateAvailableInsight: SmartInsightProviding { itunesRegion: String = Locale.current.regionCode ?? "us", appMetadataCompletion: (() -> Result)? = nil ) { - guard let bundleIdentifier = bundleIdentifier else { return nil } + guard let bundleIdentifier else { return nil } let url = URL(string: "https://itunes.apple.com/\(itunesRegion)/lookup?bundleId=\(bundleIdentifier)")! let group = DispatchGroup() @@ -29,7 +29,7 @@ struct UpdateAvailableInsight: SmartInsightProviding { var appMetadata: AppMetadata? let request = URLRequest(url: url) - if let appMetadataCompletion = appMetadataCompletion { + if let appMetadataCompletion { group.leave() switch appMetadataCompletion() { case .success(let result): @@ -40,12 +40,12 @@ struct UpdateAvailableInsight: SmartInsightProviding { } else { let task = URLSession.shared.dataTask(with: request) { data, _, _ in group.leave() - if let data = data { + if let data { let result = try? JSONDecoder().decode(AppMetadataResults.self, from: data) appMetadata = result?.results.first } } - + /// Set a timeout of 1 second to prevent the call from taking too long unexpectedly. /// Though: the request should be super fast since it's a small resource. let result = group.wait(timeout: .now() + .seconds(1)) @@ -56,7 +56,7 @@ struct UpdateAvailableInsight: SmartInsightProviding { } } - guard let appMetadata = appMetadata else { + guard let appMetadata else { return nil }