SwiftFormat redundantType

This commit is contained in:
Nindi Gill 2023-11-19 19:33:36 +11:00
parent d54898baa4
commit 46d9bd7259
No known key found for this signature in database
GPG key ID: FF9A7FD590D4F4B1
25 changed files with 64 additions and 64 deletions

View file

@ -10,13 +10,13 @@ import UserNotifications
class AppDelegate: NSObject, NSApplicationDelegate {
// swiftlint:disable:next weak_delegate
private let userNotificationCenterDelegate: UserNotificationCenterDelegate = UserNotificationCenterDelegate()
private let userNotificationCenterDelegate: UserNotificationCenterDelegate = .init()
func applicationDidFinishLaunching(_ notification: Notification) {
UNUserNotificationCenter.current().delegate = userNotificationCenterDelegate
let show: UNNotificationAction = UNNotificationAction(identifier: UNNotificationAction.Identifier.show, title: "Show", options: .foreground)
let success: UNNotificationCategory = UNNotificationCategory(identifier: UNNotificationCategory.Identifier.success, actions: [show], intentIdentifiers: [], options: [])
let failure: UNNotificationCategory = UNNotificationCategory(identifier: UNNotificationCategory.Identifier.failure, actions: [], intentIdentifiers: [], options: [])
let show: UNNotificationAction = .init(identifier: UNNotificationAction.Identifier.show, title: "Show", options: .foreground)
let success: UNNotificationCategory = .init(identifier: UNNotificationCategory.Identifier.success, actions: [show], intentIdentifiers: [], options: [])
let failure: UNNotificationCategory = .init(identifier: UNNotificationCategory.Identifier.failure, actions: [], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([success, failure])
NSWindow.allowsAutomaticWindowTabbing = false
@ -35,7 +35,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
let identifier: String = UUID().uuidString
let content: UNMutableNotificationContent = UNMutableNotificationContent()
let content: UNMutableNotificationContent = .init()
content.title = title
content.body = body
content.sound = .default
@ -46,8 +46,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
content.userInfo = ["URL": url.path]
}
let trigger: UNTimeIntervalNotificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request: UNNotificationRequest = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
let trigger: UNTimeIntervalNotificationTrigger = .init(timeInterval: 1, repeats: false)
let request: UNNotificationRequest = .init(identifier: identifier, content: content, trigger: trigger)
notificationCenter.add(request) { error in

View file

@ -36,7 +36,7 @@ extension URL {
fileHandle.closeFile()
}
var shasum: Insecure.SHA1 = Insecure.SHA1()
var shasum: Insecure.SHA1 = .init()
while try autoreleasepool(invoking: {
try Task.checkCancellation()
@ -49,7 +49,7 @@ extension URL {
return !data.isEmpty
}) { }
let data: Data = Data(shasum.finalize())
let data: Data = .init(shasum.finalize())
return data.map { String(format: "%02hhx", $0) }.joined()
} catch {
print(error.localizedDescription)

View file

@ -22,8 +22,8 @@ enum DirectoryRemover {
}
let arguments: [String] = [url.path]
let client: XPCClient = XPCClient.forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = HelperToolCommandRequest(type: .remove, arguments: arguments, environment: [:])
let client: XPCClient = .forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = .init(type: .remove, arguments: arguments, environment: [:])
let response: HelperToolCommandResponse = try await client.sendMessage(request, to: XPCRoute.commandRoute)
guard response.terminationStatus == 0 else {

View file

@ -8,9 +8,9 @@
import Foundation
class DownloadManager: NSObject, ObservableObject {
static let shared: DownloadManager = DownloadManager()
static let shared: DownloadManager = .init()
private var task: URLSessionDownloadTask?
private var progress: Progress = Progress()
private var progress: Progress = .init()
var currentValue: Double {
progress.fractionCompleted
}
@ -21,7 +21,7 @@ class DownloadManager: NSObject, ObservableObject {
return
}
let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
let semaphore: DispatchSemaphore = .init(value: 0)
var mistError: MistError?
var urlError: URLError?
var retries: Int = 0

View file

@ -23,8 +23,8 @@ enum FileAttributesUpdater {
}
let arguments: [String] = [url.path, ownerAccountName]
let client: XPCClient = XPCClient.forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = HelperToolCommandRequest(type: .fileAttributes, arguments: arguments, environment: [:])
let client: XPCClient = .forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = .init(type: .fileAttributes, arguments: arguments, environment: [:])
let response: HelperToolCommandResponse = try await client.sendMessage(request, to: XPCRoute.commandRoute)
guard response.terminationStatus == 0 else {

View file

@ -26,8 +26,8 @@ enum InstallMediaCreator {
arguments += ["--applicationpath", applicationPath]
}
let client: XPCClient = XPCClient.forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = HelperToolCommandRequest(type: .createinstallmedia, arguments: arguments, environment: [:])
let client: XPCClient = .forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = .init(type: .createinstallmedia, arguments: arguments, environment: [:])
let response: HelperToolCommandResponse = try await client.sendMessage(request, to: XPCRoute.commandRoute)
guard response.terminationStatus == 0 else {

View file

@ -49,10 +49,10 @@ enum InstallerCreator {
}
let variables: [String: String] = ["CM_BUILD": "CM_BUILD"]
let client: XPCClient = XPCClient.forMachService(named: .helperIdentifier)
let client: XPCClient = .forMachService(named: .helperIdentifier)
for arguments in argumentsArrays {
let request: HelperToolCommandRequest = HelperToolCommandRequest(type: .installer, arguments: arguments, environment: variables)
let request: HelperToolCommandRequest = .init(type: .installer, arguments: arguments, environment: variables)
let response: HelperToolCommandResponse = try await client.sendMessage(request, to: XPCRoute.commandRoute)
guard response.terminationStatus == 0 else {

View file

@ -10,9 +10,9 @@ import Foundation
/// Helper struct to perform lookups on the Privilged Helper Tool executable.
enum PrivilegedHelperTool {
/// The URL of the Privileged Helper Tool within the Mist app bundle.
static let availableURL: URL = URL(fileURLWithPath: "\(Bundle.main.bundlePath)/Contents/Library/LaunchServices/\(String.helperIdentifier)")
static let availableURL: URL = .init(fileURLWithPath: "\(Bundle.main.bundlePath)/Contents/Library/LaunchServices/\(String.helperIdentifier)")
/// The URL of the Privileged Helper Tool within /Library/PrivilegedHelperTools.
static let installedURL: URL = URL(fileURLWithPath: .helperURL)
static let installedURL: URL = .init(fileURLWithPath: .helperURL)
/// Determines if the Privileged Helper Tool is installed correctly.
///

View file

@ -13,8 +13,8 @@ enum ProcessKiller {
///
/// - Throws: A `MistError` if the process fails to be killed.
static func kill() async throws {
let client: XPCClient = XPCClient.forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = HelperToolCommandRequest(type: .kill, arguments: [], environment: [:])
let client: XPCClient = .forMachService(named: .helperIdentifier)
let request: HelperToolCommandRequest = .init(type: .kill, arguments: [], environment: [:])
let response: HelperToolCommandResponse = try await client.sendMessage(request, to: XPCRoute.commandRoute)
guard response.terminationStatus == 0 else {

View file

@ -11,7 +11,7 @@ import System
// swiftlint:disable file_length
// swiftlint:disable:next type_body_length
class TaskManager: ObservableObject {
static let shared: TaskManager = TaskManager()
static let shared: TaskManager = .init()
@Published var taskGroups: [(section: MistTaskSection, tasks: [MistTask])]
var task: Task<Any, Error> = Task { }
@ -38,7 +38,7 @@ class TaskManager: ObservableObject {
}
static func taskGroups(for firmware: Firmware, destination destinationURL: URL?, retries: Int, delay retryDelay: Int) throws -> [(section: MistTaskSection, tasks: [MistTask])] {
let temporaryDirectoryURL: URL = URL(fileURLWithPath: .temporaryDirectory)
let temporaryDirectoryURL: URL = .init(fileURLWithPath: .temporaryDirectory)
guard let destinationURL: URL = destinationURL else {
throw MistError.invalidDestinationURL
@ -145,8 +145,8 @@ class TaskManager: ObservableObject {
packageSigningIdentity: String
) throws -> [(section: MistTaskSection, tasks: [MistTask])] {
var taskGroups: [(section: MistTaskSection, tasks: [MistTask])] = []
let cacheDirectoryURL: URL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id)
let temporaryDirectoryURL: URL = URL(fileURLWithPath: .temporaryDirectory)
let cacheDirectoryURL: URL = .init(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id)
let temporaryDirectoryURL: URL = .init(fileURLWithPath: .temporaryDirectory)
guard let destinationURL: URL = destinationURL else {
throw MistError.invalidDestinationURL
@ -232,8 +232,8 @@ class TaskManager: ObservableObject {
delay retryDelay: Int,
volume: InstallerVolume
) throws -> [(section: MistTaskSection, tasks: [MistTask])] {
let cacheDirectoryURL: URL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id)
let temporaryDirectoryURL: URL = URL(fileURLWithPath: .temporaryDirectory)
let cacheDirectoryURL: URL = .init(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id)
let temporaryDirectoryURL: URL = .init(fileURLWithPath: .temporaryDirectory)
let taskGroups: [(section: MistTaskSection, tasks: [MistTask])] = [
(
section: .download,
@ -279,7 +279,7 @@ class TaskManager: ObservableObject {
throw MistError.missingFileAttributes
}
let filePermissions: FilePermissions = FilePermissions(rawValue: CModeT(posixPermissions.int16Value))
let filePermissions: FilePermissions = .init(rawValue: CModeT(posixPermissions.int16Value))
if filePermissions != [.ownerReadWriteExecute, .groupReadExecute, .otherReadExecute] || ownerAccountName != NSUserName() || groupOwnerAccountName != "wheel" {
tasks += [
@ -326,8 +326,8 @@ class TaskManager: ObservableObject {
if installer.sierraOrOlder,
let package: Package = installer.packages.first {
let legacyDiskImageURL: URL = URL(fileURLWithPath: "\(cacheDirectory)/\(installer.id)/\(package.filename)")
let legacyDiskImageMountPointURL: URL = URL(fileURLWithPath: "/Volumes/Install \(installer.name)")
let legacyDiskImageURL: URL = .init(fileURLWithPath: "\(cacheDirectory)/\(installer.id)/\(package.filename)")
let legacyDiskImageMountPointURL: URL = .init(fileURLWithPath: "/Volumes/Install \(installer.name)")
tasks += [
MistTask(type: .mount, description: "Installer Disk Image") {
@ -450,7 +450,7 @@ class TaskManager: ObservableObject {
return
}
let url: URL = URL(fileURLWithPath: "/Volumes/Install macOS \(major) beta")
let url: URL = .init(fileURLWithPath: "/Volumes/Install macOS \(major) beta")
if FileManager.default.fileExists(atPath: url.path) {
try await DiskImageUnmounter.unmount(url)
@ -518,7 +518,7 @@ class TaskManager: ObservableObject {
private static func bootableInstallerTasks(for installer: Installer, volume: InstallerVolume) -> [MistTask] {
let createInstallMediaURL: URL = installer.temporaryInstallerURL.appendingPathComponent("Contents/Resources/createinstallmedia")
let mountPointURL: URL = URL(fileURLWithPath: volume.path)
let mountPointURL: URL = .init(fileURLWithPath: volume.path)
let tasks: [MistTask] = [
MistTask(type: .create, description: "Bootable Installer") {
// Workaround to make macOS Sierra 10.12 createinstallmedia work

View file

@ -12,7 +12,7 @@ struct MistApp: App {
// swiftlint:disable:next weak_delegate
@NSApplicationDelegateAdaptor(AppDelegate.self)
var appDelegate: AppDelegate
@StateObject var sparkleUpdater: SparkleUpdater = SparkleUpdater()
@StateObject var sparkleUpdater: SparkleUpdater = .init()
@State private var refreshing: Bool = false
@State private var tasksInProgress: Bool = false

View file

@ -20,7 +20,7 @@ struct Catalog: Identifiable, Decodable, Equatable {
Catalog(type: .ventura, standard: true, customerSeed: false, developerSeed: false, publicSeed: false)
}
var id: UUID = UUID()
var id: UUID = .init()
var type: CatalogType
var standard: Bool
var customerSeed: Bool

View file

@ -61,7 +61,7 @@ struct Chunklist {
throw MistError.chunklistValidationError("Invalid file size: '\(data.count)', should be '\(size)'")
}
let array: [UInt8] = [UInt8](data)
let array: [UInt8] = .init(data)
magicHeader = array.uInt32(at: 0x00)
headerSize = array.uInt32(at: 0x04)
fileVersion = array.uInt8(at: 0x08)
@ -124,7 +124,7 @@ struct Chunklist {
for offset in 0..<totalChunks {
let size: UInt32 = array.uInt32(at: offset * 0x24)
let hash: [UInt8] = Array(array[offset * 0x24 + 0x04...(offset * 0x24 + 0x04) + 0x1F])
let chunk: Chunk = Chunk(size: size, hash: hash)
let chunk: Chunk = .init(size: size, hash: hash)
chunks.append(chunk)
}

View file

@ -8,8 +8,8 @@
import Foundation
struct InstallerVolume: Identifiable, Hashable {
static let placeholder: InstallerVolume = InstallerVolume(id: "placeholder", name: "No volume selected", path: "", capacity: 0)
static let invalid: InstallerVolume = InstallerVolume(id: "invalid", name: "No available volumes found", path: "", capacity: 0)
static let placeholder: InstallerVolume = .init(id: "placeholder", name: "No volume selected", path: "", capacity: 0)
static let invalid: InstallerVolume = .init(id: "invalid", name: "No available volumes found", path: "", capacity: 0)
var id: String
var name: String

View file

@ -8,7 +8,7 @@
import Foundation
struct MistTask: Identifiable {
let id: UUID = UUID()
let id: UUID = .init()
let type: MistTaskType
var state: MistTaskState = .pending
let description: String

View file

@ -15,7 +15,7 @@ class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate
return
}
let url: URL = URL(fileURLWithPath: string)
let url: URL = .init(fileURLWithPath: string)
NSWorkspace.shared.selectFile(url.path, inFileViewerRootedAtPath: "")
}
}

View file

@ -19,9 +19,9 @@ struct ContentView: View {
@State private var firmwares: [Firmware] = []
@State private var installers: [Installer] = []
@State private var searchString: String = ""
@State private var openPanel: NSOpenPanel = NSOpenPanel()
@State private var savePanel: NSSavePanel = NSSavePanel()
@StateObject private var taskManager: TaskManager = TaskManager.shared
@State private var openPanel: NSOpenPanel = .init()
@State private var savePanel: NSSavePanel = .init()
@StateObject private var taskManager: TaskManager = .shared
private var filteredFirmwares: [Firmware] {
var filteredFirmwares: [Firmware] = firmwares

View file

@ -13,9 +13,9 @@ struct FooterView: View {
var downloadType: DownloadType
@Binding var firmwares: [Firmware]
@Binding var installers: [Installer]
@State private var savePanel: NSSavePanel = NSSavePanel()
@State private var savePanel: NSSavePanel = .init()
@State private var exportListType: ExportListType = .json
private let dateFormatter: DateFormatter = DateFormatter()
private let dateFormatter: DateFormatter = .init()
var body: some View {
HStack {

View file

@ -82,7 +82,7 @@ struct InstallerVolumeSelectionView: View {
continue
}
let volume: InstallerVolume = InstallerVolume(id: UUID().uuidString, name: volumeName, path: url.path, capacity: UInt64(volumeTotalCapacity))
let volume: InstallerVolume = .init(id: UUID().uuidString, name: volumeName, path: url.path, capacity: UInt64(volumeTotalCapacity))
volumes.append(volume)
} catch {
continue
@ -93,7 +93,7 @@ struct InstallerVolumeSelectionView: View {
}
private func openDiskUtility() {
let url: URL = URL(fileURLWithPath: "/System/Applications/Utilities/Disk Utility.app")
let url: URL = .init(fileURLWithPath: "/System/Applications/Utilities/Disk Utility.app")
NSWorkspace.shared.open(url)
}
}

View file

@ -257,7 +257,7 @@ struct ListRowInstaller: View {
return
}
let filePermissions: FilePermissions = FilePermissions(rawValue: CModeT(posixPermissions.int16Value))
let filePermissions: FilePermissions = .init(rawValue: CModeT(posixPermissions.int16Value))
guard filePermissions == [.ownerReadWriteExecute, .groupReadExecute, .otherReadExecute],
let ownerAccountName: String = attributes[.ownerAccountName] as? String,
@ -304,7 +304,7 @@ struct ListRowInstaller: View {
}
private func repairCacheDirectoryOwnershipAndPermissions() async throws {
let url: URL = URL(fileURLWithPath: cacheDirectory)
let url: URL = .init(fileURLWithPath: cacheDirectory)
let ownerAccountName: String = NSUserName()
try await FileAttributesUpdater.update(url: url, ownerAccountName: ownerAccountName)
}

View file

@ -203,7 +203,7 @@ struct RefreshView: View {
let catalogTypes: [CatalogType] = catalogs.map { $0.type }
for catalogType in CatalogType.allCases where !catalogTypes.contains(catalogType) {
let catalog: Catalog = Catalog(type: catalogType, standard: true, customerSeed: false, developerSeed: false, publicSeed: false)
let catalog: Catalog = .init(type: catalogType, standard: true, customerSeed: false, developerSeed: false, publicSeed: false)
catalogs.append(catalog)
}
} catch {
@ -236,7 +236,7 @@ struct RefreshView: View {
private func getInstallers(from dictionary: [String: Any]) -> [Installer] {
var installers: [Installer] = []
let dateFormatter: DateFormatter = DateFormatter()
let dateFormatter: DateFormatter = .init()
dateFormatter.dateFormat = "yyyy-MM-dd"
for (key, value) in dictionary {

View file

@ -55,7 +55,7 @@ struct SettingsGeneralNotificationsView: View {
}
private func request() {
let userNotificationCenter: UNUserNotificationCenter = UNUserNotificationCenter.current()
let userNotificationCenter: UNUserNotificationCenter = .current()
let options: UNAuthorizationOptions = [.alert, .badge, .sound]
userNotificationCenter.requestAuthorization(options: options) { success, _ in

View file

@ -11,7 +11,7 @@ struct SettingsInstallersCacheView: View {
@Binding var cacheDownloads: Bool
@Binding var cacheDirectory: String
@State private var cacheSize: UInt64 = 0
@State private var openPanel: NSOpenPanel = NSOpenPanel()
@State private var openPanel: NSOpenPanel = .init()
@State private var installers: [Installer] = []
@State private var selectedInstallerId: String?
@State private var showAlert: Bool = false
@ -106,7 +106,7 @@ struct SettingsInstallersCacheView: View {
}
private func retrieveCache() {
let url: URL = URL(fileURLWithPath: cacheDirectory)
let url: URL = .init(fileURLWithPath: cacheDirectory)
var isDirectory: ObjCBool = false
do {
@ -214,7 +214,7 @@ struct SettingsInstallersCacheView: View {
return
}
let url: URL = URL(fileURLWithPath: "\(cacheDirectory)/\(id)")
let url: URL = .init(fileURLWithPath: "\(cacheDirectory)/\(id)")
NSWorkspace.shared.open(url)
}
@ -223,7 +223,7 @@ struct SettingsInstallersCacheView: View {
return
}
let url: URL = URL(fileURLWithPath: "\(cacheDirectory)/\(id)")
let url: URL = .init(fileURLWithPath: "\(cacheDirectory)/\(id)")
do {
try await DirectoryRemover.remove(url)

View file

@ -51,7 +51,7 @@ struct SettingsInstallersView: View {
let catalogTypes: [CatalogType] = catalogs.map { $0.type }
for catalogType in CatalogType.allCases where !catalogTypes.contains(catalogType) {
let catalog: Catalog = Catalog(type: catalogType, standard: true, customerSeed: false, developerSeed: false, publicSeed: false)
let catalog: Catalog = .init(type: catalogType, standard: true, customerSeed: false, developerSeed: false, publicSeed: false)
catalogs.append(catalog)
}

View file

@ -9,8 +9,8 @@ import Foundation
/// Helper class used to execute shell commands.
class ShellExecutor: NSObject {
static var shared: ShellExecutor = ShellExecutor()
private var process: Process = Process()
static var shared: ShellExecutor = .init()
private var process: Process = .init()
/// Executes custom shell commands.
///
@ -27,8 +27,8 @@ class ShellExecutor: NSObject {
environment variables: [String: String] = [:],
currentDirectoryPath: String? = nil
) throws -> HelperToolCommandResponse {
let outputPipe: Pipe = Pipe()
let errorPipe: Pipe = Pipe()
let outputPipe: Pipe = .init()
let errorPipe: Pipe = .init()
process = Process()
process.launchPath = "/usr/bin/env"
process.arguments = arguments