Skip to content

Commit

Permalink
Clean up the project by fixing SwiftLint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
AvdLee committed Apr 24, 2023
1 parent cd1c684 commit cfdb1ed
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Diagnostics.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 5 additions & 3 deletions Example/Diagnostics-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -141,8 +141,9 @@
500B276C23953F8C00C304D4 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1120;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = WeTransfer;
TargetAttributes = {
500B277323953F8C00C304D4 = {
Expand Down Expand Up @@ -184,6 +185,7 @@
/* Begin PBXShellScriptBuildPhase section */
84E8B49F289179FC00A84288 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -198,7 +200,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [ -z \"$CI\" ]; then\n if [ \"${CONFIGURATION}\" == \"Debug\" ]; then\n if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\n fi\n\n export PATH\n swiftlint --config \"${SRCROOT}/../Submodules/WeTransfer-iOS-CI/BuildTools/.swiftlint.yml\"\n swiftlint lint --path ../Sources --config \"${SRCROOT}/../Submodules/WeTransfer-iOS-CI/BuildTools/.swiftlint.yml\"\n else\n echo \"Info: As we're not building for Debug, no SwiftLint is running.\"\n fi\nfi\n";
shellScript = "if [ -z \"$CI\" ]; then\n if [ \"${CONFIGURATION}\" == \"Debug\" ]; then\n if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\n fi\n\n export PATH\n swiftlint --config \"${SRCROOT}/../Submodules/WeTransfer-iOS-CI/BuildTools/.swiftlint.yml\"\n swiftlint lint --config \"${SRCROOT}/../Submodules/WeTransfer-iOS-CI/BuildTools/.swiftlint.yml\" ../Sources\n else\n echo \"Info: As we're not building for Debug, no SwiftLint is running.\"\n fi\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Example/Diagnostics-Example/CustomFilters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import Foundation
import Diagnostics
import Foundation

struct DiagnosticsDictionaryFilter: DiagnosticsReportFilter {

Expand Down
4 changes: 2 additions & 2 deletions Example/Diagnostics-Example/CustomReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import Foundation
import Diagnostics
import Foundation

enum Session {
/// A fake property to demonstrate the custom reporter.
static var isLoggedIn: Bool = false
static var isLoggedIn = false
}

/// An example Custom Reporter.
Expand Down
2 changes: 1 addition & 1 deletion Example/Diagnostics-Example/CustomSmartInsights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import Foundation
import Diagnostics
import Foundation

struct SmartInsightsProvider: SmartInsightsProviding {
func smartInsights(for chapter: DiagnosticsChapter) -> [SmartInsightProviding] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions Example/Diagnostics-Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import UIKit
import MessageUI
import Diagnostics
import MessageUI
import UIKit

final class ViewController: UIViewController {

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Sources/DiagnosticsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/HTMLGenerating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension DiagnosticsChapter: HTMLGenerating {

html += "<div class=\"chapter-content\">"

if let formatter = formatter {
if let formatter {
html += formatter.format(diagnostics)
} else {
html += diagnostics.html()
Expand Down
18 changes: 9 additions & 9 deletions Sources/Logging/DiagnosticsLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import ExceptionCatcher
import Foundation
import MetricKit
import ExceptionCatcher

#if os(macOS)
import AppKit
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
})
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Logging/Loggable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension Loggable {
var cssClass: LoggableCSSClass? { nil }

var logData: Data? {
if let cssClass = cssClass {
if let cssClass {
return "<p class=\"\(cssClass)\">\(logMessage)</p>\n".data(using: .utf8)
} else {
return "\(message)\n".data(using: .utf8)
Expand All @@ -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("<span class=\"log-date\">\(date)</span>")
}
if let prefix = prefix {
if let prefix {
messages.append("<span class=\"log-prefix\">\(prefix)</span>")
}
messages.append("<span class=\"log-message\">\(self.message)</span>")
Expand Down Expand Up @@ -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)"
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Reporters/AppSystemMetadataReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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] {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Reporters/DirectoryTree/DirectoryTreeFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/Reporters/DirectoryTree/DirectoryTreeReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,7 @@ public struct DirectoryTreesReporter: DiagnosticsReporting {
}
self.init(trunks: newTrunks)
}

public init(trunks: [Directory]) {
self.trunks = trunks
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions Sources/Reporters/SmartInsightsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmartInsights/CellularAllowedInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions Sources/SmartInsights/UpdateAvailableInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ struct UpdateAvailableInsight: SmartInsightProviding {
itunesRegion: String = Locale.current.regionCode ?? "us",
appMetadataCompletion: (() -> Result<AppMetadataResults, Error>)? = 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()
group.enter()

var appMetadata: AppMetadata?
let request = URLRequest(url: url)
if let appMetadataCompletion = appMetadataCompletion {
if let appMetadataCompletion {
group.leave()
switch appMetadataCompletion() {
case .success(let result):
Expand All @@ -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))
Expand All @@ -56,7 +56,7 @@ struct UpdateAvailableInsight: SmartInsightProviding {
}
}

guard let appMetadata = appMetadata else {
guard let appMetadata else {
return nil
}

Expand Down

0 comments on commit cfdb1ed

Please sign in to comment.