diff --git a/.swiftformat b/.swiftformat index f50eba4f..3cc61aed 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,4 +1,4 @@ ---swiftversion 5.2 +--swiftversion 5.3 --exclude Carthage,third-party,**/*.generated.swift @@ -7,3 +7,4 @@ --self insert --wraparguments before-first +--ranges no-space diff --git a/Commons/Package.swift b/Commons/Package.swift index f31008c0..b86eac71 100644 --- a/Commons/Package.swift +++ b/Commons/Package.swift @@ -15,7 +15,7 @@ let package = Package( name: "CommonsTests", dependencies: ["Commons", "Nimble"], resources: [ - .copy("Resources") + .copy("Resources"), ] ), ] diff --git a/Commons/Sources/Commons/AppKitCommons.swift b/Commons/Sources/Commons/AppKitCommons.swift index 2dda31d6..0a8fb5c9 100644 --- a/Commons/Sources/Commons/AppKitCommons.swift +++ b/Commons/Sources/Commons/AppKitCommons.swift @@ -6,7 +6,6 @@ import AppKit public extension NSAttributedString { - func draw(at point: CGPoint, angle: CGFloat) { var translation = AffineTransform.identity var rotation = AffineTransform.identity @@ -30,7 +29,6 @@ public extension NSAttributedString { } public extension NSColor { - static var random: NSColor { NSColor( calibratedRed: .random(in: 0...1), @@ -56,9 +54,9 @@ public extension NSColor { convenience init(rgb: Int) { // @formatter:off - let red = ((rgb >> 16) & 0xFF).cgf / 255.0; - let green = ((rgb >> 8) & 0xFF).cgf / 255.0; - let blue = ((rgb ) & 0xFF).cgf / 255.0; + let red = ((rgb >> 16) & 0xFF).cgf / 255.0 + let green = ((rgb >> 8) & 0xFF).cgf / 255.0 + let blue = (rgb & 0xFF).cgf / 255.0 // @formatter:on self.init(srgbRed: red, green: green, blue: blue, alpha: 1.0) @@ -88,7 +86,6 @@ public extension NSColor { } public extension NSImage { - func tinting(with color: NSColor) -> NSImage { let result = self.copy() as! NSImage @@ -102,7 +99,6 @@ public extension NSImage { } public extension NSButton { - var boolState: Bool { get { self.state == .on ? true : false } set { self.state = newValue ? .on : .off } @@ -110,7 +106,6 @@ public extension NSButton { } public extension NSMenuItem { - var boolState: Bool { get { self.state == .on ? true : false } set { self.state = newValue ? .on : .off } @@ -118,17 +113,16 @@ public extension NSMenuItem { } public extension NSView { - func removeAllSubviews() { self.subviews.forEach { $0.removeFromSuperview() } } func removeAllConstraints() { self.removeConstraints(self.constraints) } func beFirstResponder() { self.window?.makeFirstResponder(self) } - + /// - Returns: Rects currently being drawn /// - Warning: Call only in drawRect() func rectsBeingDrawn() -> [CGRect] { - var rectsPtr: UnsafePointer? = nil + var rectsPtr: UnsafePointer? var count: Int = 0 self.getRectsBeingDrawn(&rectsPtr, count: &count) @@ -137,16 +131,15 @@ public extension NSView { } public extension NSEvent.ModifierFlags { - // Values are from https://github.com/SFML/SFML/blob/master/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm // @formatter:off - static let rightShift = NSEvent.ModifierFlags(rawValue: 0x020004) - static let leftShift = NSEvent.ModifierFlags(rawValue: 0x020002) + static let rightShift = NSEvent.ModifierFlags(rawValue: 0x020004) + static let leftShift = NSEvent.ModifierFlags(rawValue: 0x020002) static let rightCommand = NSEvent.ModifierFlags(rawValue: 0x100010) - static let leftCommand = NSEvent.ModifierFlags(rawValue: 0x100008) - static let rightOption = NSEvent.ModifierFlags(rawValue: 0x080040) - static let leftOption = NSEvent.ModifierFlags(rawValue: 0x080020) + static let leftCommand = NSEvent.ModifierFlags(rawValue: 0x100008) + static let rightOption = NSEvent.ModifierFlags(rawValue: 0x080040) + static let leftOption = NSEvent.ModifierFlags(rawValue: 0x080020) static let rightControl = NSEvent.ModifierFlags(rawValue: 0x042000) - static let leftControl = NSEvent.ModifierFlags(rawValue: 0x040001) + static let leftControl = NSEvent.ModifierFlags(rawValue: 0x040001) // @formatter:on } diff --git a/Commons/Sources/Commons/ConditionVariable.swift b/Commons/Sources/Commons/ConditionVariable.swift index 83767c32..610a6060 100644 --- a/Commons/Sources/Commons/ConditionVariable.swift +++ b/Commons/Sources/Commons/ConditionVariable.swift @@ -6,14 +6,13 @@ import Foundation public final class ConditionVariable { - private(set) var posted: Bool public init(posted: Bool = false) { self.posted = posted } - public func wait(`for` seconds: TimeInterval, then fn: (() -> Void)? = nil) { + public func wait(for seconds: TimeInterval, then fn: (() -> Void)? = nil) { self.condition.lock() defer { self.condition.unlock() } diff --git a/Commons/Sources/Commons/CoreCommons.swift b/Commons/Sources/Commons/CoreCommons.swift index f012984f..9c945ec8 100644 --- a/Commons/Sources/Commons/CoreCommons.swift +++ b/Commons/Sources/Commons/CoreCommons.swift @@ -6,23 +6,19 @@ import Foundation public extension CFRange { - static let zero = CFRange(location: 0, length: 0) } public extension CGSize { - func scaling(_ factor: CGFloat) -> CGSize { - return CGSize(width: self.width * factor, height: self.height * factor) + CGSize(width: self.width * factor, height: self.height * factor) } } public extension CGRect { - var hashValue: Int { let o = Int(self.origin.x) << 10 ^ Int(self.origin.y) let s = Int(self.size.width) << 10 ^ Int(self.size.height) return o + s } } - diff --git a/Commons/Sources/Commons/Defs.swift b/Commons/Sources/Commons/Defs.swift index a303ff63..40893859 100644 --- a/Commons/Sources/Commons/Defs.swift +++ b/Commons/Sources/Commons/Defs.swift @@ -6,11 +6,9 @@ import Foundation struct Defs { - static let loggerSubsystem = "com.qvacua.Commons" struct LoggerCategory { - static let general = "general" } } diff --git a/Commons/Sources/Commons/FifoCache.swift b/Commons/Sources/Commons/FifoCache.swift index dc8da21f..092d8d1e 100644 --- a/Commons/Sources/Commons/FifoCache.swift +++ b/Commons/Sources/Commons/FifoCache.swift @@ -6,7 +6,6 @@ import Foundation public final class FifoCache { - public init(count: Int, queueQos: DispatchQoS) { self.count = count self.keyWriteIndex = 0 @@ -35,9 +34,9 @@ public final class FifoCache { public func valueForKey(_ key: Key) -> Value? { self.queue.sync { self.storage[key] } } private let count: Int - private var keys: Array + private var keys: [Key?] private var keyWriteIndex: Int - private var storage: Dictionary + private var storage: [Key: Value] private let queue: DispatchQueue } diff --git a/Commons/Sources/Commons/FileUtils.swift b/Commons/Sources/Commons/FileUtils.swift index 8b6ffe6f..17457978 100644 --- a/Commons/Sources/Commons/FileUtils.swift +++ b/Commons/Sources/Commons/FileUtils.swift @@ -9,36 +9,36 @@ private let workspace = NSWorkspace.shared private let iconsCache = NSCache() public final class FileUtils { - private static let keysToGet: [URLResourceKey] = [ .isDirectoryKey, .isHiddenKey, .isAliasFileKey, - .isSymbolicLinkKey + .isSymbolicLinkKey, ] - + private static let scanOptions: FileManager.DirectoryEnumerationOptions = [ .skipsSubdirectoryDescendants, - .skipsPackageDescendants + .skipsPackageDescendants, ] - + private static let fileManager = FileManager.default public static let userHomeUrl = URL(fileURLWithPath: NSHomeDirectory(), isDirectory: true) - public static func tempDir() -> URL { URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) } + public static func tempDir() + -> URL { URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) } public static func directDescendants(of url: URL) -> [URL] { guard let childUrls = try? self.fileManager.contentsOfDirectory( at: url, includingPropertiesForKeys: self.keysToGet, options: self.scanOptions ) else { - // FIXME error handling + // FIXME: error handling return [] } - + return childUrls } - + public static func fileExists(at url: URL) -> Bool { guard url.isFileURL else { return false @@ -54,9 +54,9 @@ public final class FileUtils { } let pathComps = urls.map { $0.deletingLastPathComponent().pathComponents } - let min = pathComps.map { $0.count }.min()! + let min = pathComps.map(\.count).min()! let pathCompsOnlyMin = pathComps.map { $0[0.. 1 { return idx - 1 } else { @@ -71,7 +71,7 @@ public final class FileUtils { } public static func icon(forType type: String) -> NSImage { - return workspace.icon(forFileType: type) + workspace.icon(forFileType: type) } public static func icon(forUrl url: URL) -> NSImage? { diff --git a/Commons/Sources/Commons/FoundationCommons.swift b/Commons/Sources/Commons/FoundationCommons.swift index a8daad58..b589859f 100644 --- a/Commons/Sources/Commons/FoundationCommons.swift +++ b/Commons/Sources/Commons/FoundationCommons.swift @@ -7,7 +7,6 @@ import Foundation import os public extension Array where Element: Hashable { - // From https://stackoverflow.com/a/46354989/9850227 func uniqued() -> [Element] { var seen = Set() @@ -16,14 +15,12 @@ public extension Array where Element: Hashable { } public extension Array { - func data() -> Data { - return self.withUnsafeBufferPointer(Data.init) + self.withUnsafeBufferPointer(Data.init) } } public extension RandomAccessCollection where Index == Int { - func parallelMap( chunkSize: Int = 1, _ transform: @escaping (Element) -> T @@ -31,7 +28,7 @@ public extension RandomAccessCollection where Index == Int { let count = self.count guard count > chunkSize else { return self.map(transform) } - var result = Array(repeating: nil, count: count) + var result = [T?](repeating: nil, count: count) // If we don't use Array.withUnsafeMutableBufferPointer, // then we get crashes. @@ -97,16 +94,14 @@ public extension RandomAccessCollection where Index == Int { } public extension NSRange { - static let notFound = NSRange(location: NSNotFound, length: 0) var inclusiveEndIndex: Int { self.location + self.length - 1 } } public extension URL { - func isDirectParent(of url: URL) -> Bool { - guard self.isFileURL && url.isFileURL else { return false } + guard self.isFileURL, url.isFileURL else { return false } let myPathComps = self.pathComponents let targetPathComps = url.pathComponents @@ -117,7 +112,7 @@ public extension URL { } func isParent(of url: URL) -> Bool { - guard self.isFileURL && url.isFileURL else { return false } + guard self.isFileURL, url.isFileURL else { return false } let myPathComps = self.pathComponents let targetPathComps = url.pathComponents @@ -165,7 +160,7 @@ public extension URL { do { try (self as NSURL).getResourceValue(&rsrc, forKey: URLResourceKey(rawValue: key)) } catch let error as NSError { - // FIXME error handling + // FIXME: error handling log.error("ERROR while getting \(key): \(error)") return false } @@ -177,7 +172,6 @@ public extension URL { } public extension ValueTransformer { - static var keyedUnarchiveFromDataTransformer = ValueTransformer(forName: .keyedUnarchiveFromDataTransformerName)! } diff --git a/Commons/Sources/Commons/OSLogCommons.swift b/Commons/Sources/Commons/OSLogCommons.swift index 6f533583..b0348efc 100644 --- a/Commons/Sources/Commons/OSLogCommons.swift +++ b/Commons/Sources/Commons/OSLogCommons.swift @@ -7,7 +7,6 @@ import Foundation import os public extension OSLog { - func trace( file: String = #file, function: String = #function, @@ -15,11 +14,11 @@ public extension OSLog { _ msg: T ) { #if TRACE - self.log( - type: .debug, - msg: "%{public}@", - "[\((file as NSString).lastPathComponent) - \(function):\(line)] [TRACE] \(msg)" - ) + self.log( + type: .debug, + msg: "%{public}@", + "[\((file as NSString).lastPathComponent) - \(function):\(line)] [TRACE] \(msg)" + ) #endif } @@ -29,11 +28,11 @@ public extension OSLog { line: Int = #line ) { #if DEBUG - self.log( - type: .debug, - msg: "%{public}@", - "[\((file as NSString).lastPathComponent) - \(function):\(line)]" - ) + self.log( + type: .debug, + msg: "%{public}@", + "[\((file as NSString).lastPathComponent) - \(function):\(line)]" + ) #endif } @@ -44,11 +43,11 @@ public extension OSLog { _ msg: T ) { #if DEBUG - self.log( - type: .debug, - msg: "%{public}@", - "[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)" - ) + self.log( + type: .debug, + msg: "%{public}@", + "[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)" + ) #endif } diff --git a/Commons/Sources/Commons/ProcessUtils.swift b/Commons/Sources/Commons/ProcessUtils.swift index 1bce26d9..0eacbef9 100644 --- a/Commons/Sources/Commons/ProcessUtils.swift +++ b/Commons/Sources/Commons/ProcessUtils.swift @@ -7,7 +7,6 @@ import Foundation import os public final class ProcessUtils { - public static func envVars( of shellPath: URL, usingInteractiveMode: Bool ) -> [String: String] { @@ -57,12 +56,16 @@ public final class ProcessUtils { .trimmingCharacters(in: .whitespacesAndNewlines) .split(separator: "\n") .reduce(into: [:]) { result, entry in - let split = entry.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false).map { String($0) } + let split = entry + .split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false) + .map { String($0) } guard split.count > 1 else { return } result[split[0]] = split[1] } } - private static let logger = OSLog(subsystem: Defs.loggerSubsystem, - category: Defs.LoggerCategory.general) + private static let logger = OSLog( + subsystem: Defs.loggerSubsystem, + category: Defs.LoggerCategory.general + ) } diff --git a/Commons/Sources/Commons/SwiftCommons.swift b/Commons/Sources/Commons/SwiftCommons.swift index 6b74a97e..db01eb85 100644 --- a/Commons/Sources/Commons/SwiftCommons.swift +++ b/Commons/Sources/Commons/SwiftCommons.swift @@ -8,21 +8,18 @@ import Foundation public func identity(_ input: T) -> T { input } public extension BinaryFloatingPoint { - @inlinable @inline(__always) var cgf: CGFloat { CGFloat(self) } } public extension FixedWidthInteger { - @inlinable @inline(__always) var cgf: CGFloat { CGFloat(self) } } public extension String { - func without(prefix: String) -> String { guard self.hasPrefix(prefix) else { return self } @@ -32,7 +29,6 @@ public extension String { } public extension Array where Element: Equatable { - func removingDuplicatesPreservingFromBeginning() -> [Element] { var result = [Element]() @@ -62,9 +58,8 @@ public extension Array where Element: Equatable { } public extension Array where Element: Hashable { - - func toDict(by mapper: @escaping (Element) -> V) -> Dictionary { - var result = Dictionary(minimumCapacity: self.count) + func toDict(by mapper: @escaping (Element) -> V) -> [Element: V] { + var result = [Element: V](minimumCapacity: self.count) self.forEach { result[$0] = mapper($0) } return result @@ -78,8 +73,9 @@ public extension Array where Element: Hashable { } func tuplesToDict(_ sequence: S) - -> Dictionary where S.Iterator.Element == (K, V) { - var result = Dictionary(minimumCapacity: sequence.underestimatedCount) + -> [K: V] where S.Iterator.Element == (K, V) +{ + var result = [K: V](minimumCapacity: sequence.underestimatedCount) for (key, value) in sequence { result[key] = value } @@ -87,22 +83,22 @@ func tuplesToDict(_ sequence: S) } public extension Dictionary { - func mapToDict(_ transform: ((key: Key, value: Value)) throws -> (K, V)) rethrows - -> Dictionary { + -> [K: V] + { let array = try self.map(transform) return tuplesToDict(array) } func flatMapToDict(_ transform: ((key: Key, value: Value)) throws -> (K, V)?) rethrows - -> Dictionary { + -> [K: V] + { let array = try self.compactMap(transform) return tuplesToDict(array) } } public extension Sequence { - @discardableResult func log() -> Self { self.forEach { Swift.print($0) } diff --git a/Commons/Support/EnvVarTest/AppDelegate.swift b/Commons/Support/EnvVarTest/AppDelegate.swift index f9d4e40b..a566cc08 100644 --- a/Commons/Support/EnvVarTest/AppDelegate.swift +++ b/Commons/Support/EnvVarTest/AppDelegate.swift @@ -8,15 +8,14 @@ import Commons @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { + @IBOutlet var window: NSWindow! + @IBOutlet var textView: NSTextView! - @IBOutlet weak var window: NSWindow! - @IBOutlet weak var textView: NSTextView! - - func applicationDidFinishLaunching(_ aNotification: Notification) { + func applicationDidFinishLaunching(_: Notification) { let selfEnv = ProcessInfo.processInfo.environment let shellUrl = URL(fileURLWithPath: selfEnv["SHELL"] ?? "/bin/bash") let env = ProcessUtils.envVars(of: shellUrl, usingInteractiveMode: false) - + for (k, v) in env { let str = NSAttributedString(string: "\(k): \(v)\n") print(str) diff --git a/Commons/Tests/CommonsTests/ArrayCommonsTest.swift b/Commons/Tests/CommonsTests/ArrayCommonsTest.swift index b0e1d0f2..4528eb54 100644 --- a/Commons/Tests/CommonsTests/ArrayCommonsTest.swift +++ b/Commons/Tests/CommonsTests/ArrayCommonsTest.swift @@ -3,19 +3,18 @@ * See LICENSE */ -import XCTest import Nimble +import XCTest @testable import Commons -fileprivate class DummyToken: Comparable { - - static func ==(left: DummyToken, right: DummyToken) -> Bool { - return left.value == right.value +private class DummyToken: Comparable { + static func == (left: DummyToken, right: DummyToken) -> Bool { + left.value == right.value } - static func <(left: DummyToken, right: DummyToken) -> Bool { - return left.value < right.value + static func < (left: DummyToken, right: DummyToken) -> Bool { + left.value < right.value } let value: String @@ -26,18 +25,17 @@ fileprivate class DummyToken: Comparable { } class ArrayCommonsTest: XCTestCase { - func testTuplesToDict() { let tuples = [ (1, "1"), (2, "2"), - (3, "3") + (3, "3"), ] expect(tuplesToDict(tuples)).to(equal( [ 1: "1", 2: "2", - 3: "3" + 3: "3", ] )) } @@ -49,7 +47,7 @@ class ArrayCommonsTest: XCTestCase { [ 1: "1", 2: "2", - 3: "3" + 3: "3", ] )) } @@ -63,7 +61,7 @@ class ArrayCommonsTest: XCTestCase { let substitute = [ DummyToken("a0"), DummyToken("a1"), - DummyToken("a2") + DummyToken("a2"), ] let array = [ @@ -88,7 +86,7 @@ class ArrayCommonsTest: XCTestCase { let substitute = [ DummyToken("a0"), DummyToken("a1"), - DummyToken("a2") + DummyToken("a2"), ] let array = [ @@ -113,7 +111,7 @@ class ArrayCommonsTest: XCTestCase { let substitute = [ DummyToken("a0"), DummyToken("a1"), - DummyToken("a2") + DummyToken("a2"), ] let array = [ @@ -138,7 +136,7 @@ class ArrayCommonsTest: XCTestCase { let substitute = [ DummyToken("a0"), DummyToken("a1"), - DummyToken("a2") + DummyToken("a2"), ] let array = [ diff --git a/Commons/Tests/CommonsTests/DictionaryCommonsTest.swift b/Commons/Tests/CommonsTests/DictionaryCommonsTest.swift index 497f3bd3..2d6060c2 100644 --- a/Commons/Tests/CommonsTests/DictionaryCommonsTest.swift +++ b/Commons/Tests/CommonsTests/DictionaryCommonsTest.swift @@ -3,22 +3,21 @@ * See LICENSE */ -import XCTest import Nimble +import XCTest class DictionaryCommonsTest: XCTestCase { - func testMapToDict() { let dict = [ 1: "a", 2: "b", - 3: "c" + 3: "c", ] - expect(dict.mapToDict { (k, v) in (v, "\(k)-\(v)") }).to(equal( + expect(dict.mapToDict { k, v in (v, "\(k)-\(v)") }).to(equal( [ "a": "1-a", "b": "2-b", - "c": "3-c" + "c": "3-c", ] )) } @@ -27,9 +26,9 @@ class DictionaryCommonsTest: XCTestCase { let dict = [ 1: "a", 2: "b", - 3: "c" + 3: "c", ] - expect(dict.flatMapToDict { (k, v) in + expect(dict.flatMapToDict { k, v in if k == 2 { return nil } @@ -38,7 +37,7 @@ class DictionaryCommonsTest: XCTestCase { }).to(equal( [ "a": "1-a", - "c": "3-c" + "c": "3-c", ] )) } diff --git a/Commons/Tests/CommonsTests/FifoCacheTest.swift b/Commons/Tests/CommonsTests/FifoCacheTest.swift index c5378c81..410547d0 100644 --- a/Commons/Tests/CommonsTests/FifoCacheTest.swift +++ b/Commons/Tests/CommonsTests/FifoCacheTest.swift @@ -3,13 +3,12 @@ * See LICENSE */ -import XCTest import Nimble +import XCTest @testable import Commons class FifoCacheTest: XCTestCase { - var fifo: FifoCache! override func setUp() { @@ -18,15 +17,15 @@ class FifoCacheTest: XCTestCase { } func testSimpleGet() { - for i in (0...5) { self.fifo.set(i, forKey: i) } + for i in 0...5 { self.fifo.set(i, forKey: i) } - for i in (0...5) { expect(self.fifo.valueForKey(i)).to(equal(i)) } - for i in (6..<10) { expect(self.fifo.valueForKey(i)).to(beNil()) } + for i in 0...5 { expect(self.fifo.valueForKey(i)).to(equal(i)) } + for i in 6..<10 { expect(self.fifo.valueForKey(i)).to(beNil()) } } func testGet() { - for i in (0..<(10 * 3)) { self.fifo.set(i, forKey: i) } - for i in (20..<30) { expect(self.fifo.valueForKey(i)).to(equal(i)) } + for i in 0..<(10 * 3) { self.fifo.set(i, forKey: i) } + for i in 20..<30 { expect(self.fifo.valueForKey(i)).to(equal(i)) } expect(self.fifo.valueForKey(19)).to(beNil()) expect(self.fifo.valueForKey(30)).to(beNil()) } diff --git a/Commons/Tests/CommonsTests/FileUtilsTest.swift b/Commons/Tests/CommonsTests/FileUtilsTest.swift index 4402b46c..a59392ef 100644 --- a/Commons/Tests/CommonsTests/FileUtilsTest.swift +++ b/Commons/Tests/CommonsTests/FileUtilsTest.swift @@ -3,19 +3,22 @@ * See LICENSE */ -import XCTest import Nimble +import XCTest @testable import Commons class FileUtilsTest: XCTestCase { - var fileUtilsRsrcUrl = URL(fileURLWithPath: "/") var a1Dir = URL(fileURLWithPath: "/") override func setUp() { - fileUtilsRsrcUrl = Bundle.module.url(forResource: "FileUtilsTest", withExtension: "", subdirectory: "Resources")! - a1Dir = fileUtilsRsrcUrl.appendingPathComponent("a1") + self.fileUtilsRsrcUrl = Bundle.module.url( + forResource: "FileUtilsTest", + withExtension: "", + subdirectory: "Resources" + )! + self.a1Dir = self.fileUtilsRsrcUrl.appendingPathComponent("a1") } func testCommonParentOneDirUrl() { @@ -23,7 +26,7 @@ class FileUtilsTest: XCTestCase { fileUtilsRsrcUrl.appendingPathComponent("a1"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl)) } func testCommonParentOneFileUrl() { @@ -31,77 +34,78 @@ class FileUtilsTest: XCTestCase { fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(a1Dir)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.a1Dir)) } func testCommonParentEmptyParams() { - expect(FileUtils.commonParent(of: []) as URL).to(equal(URL(fileURLWithPath: "/", isDirectory: true))) + expect(FileUtils.commonParent(of: []) as URL) + .to(equal(URL(fileURLWithPath: "/", isDirectory: true))) } func testCommonParent1() { let urls = [ fileUtilsRsrcUrl.appendingPathComponent("a1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl)) } func testCommonParent2() { let urls = [ fileUtilsRsrcUrl.appendingPathComponent("a1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl)) } func testBug1() { let paths = [ fileUtilsRsrcUrl.appendingPathComponent("Downloads/test2/some/nginx.config"), - fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config") + self.fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config"), ] - expect(FileUtils.commonParent(of: paths)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: paths)).to(equal(self.fileUtilsRsrcUrl)) } func testBug2() { let paths = [ fileUtilsRsrcUrl.appendingPathComponent("Downloads/test2/some/nginx.config"), - fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config/de/nginx.config") + self.fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config/de/nginx.config"), ] - expect(FileUtils.commonParent(of: paths)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: paths)).to(equal(self.fileUtilsRsrcUrl)) } func testCommonParent3() { let urls = [ fileUtilsRsrcUrl.appendingPathComponent("a1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), - fileUtilsRsrcUrl.appendingPathComponent("b1/b1-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("b1/b1-file1"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl)) } func testCommonParent4() { let urls = [ fileUtilsRsrcUrl.appendingPathComponent("a1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), - fileUtilsRsrcUrl.appendingPathComponent("b1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("b1"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl)) } func testCommonParent5() { let urls = [ fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), - fileUtilsRsrcUrl.appendingPathComponent("a1/a2"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"), + self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2"), ] - expect(FileUtils.commonParent(of: urls)).to(equal(a1Dir)) + expect(FileUtils.commonParent(of: urls)).to(equal(self.a1Dir)) } } diff --git a/Commons/Tests/CommonsTests/StringCommonsTest.swift b/Commons/Tests/CommonsTests/StringCommonsTest.swift index d3f40fb6..fdb83c21 100644 --- a/Commons/Tests/CommonsTests/StringCommonsTest.swift +++ b/Commons/Tests/CommonsTests/StringCommonsTest.swift @@ -3,11 +3,10 @@ * See LICENSE */ -import XCTest import Nimble +import XCTest class StringCommonsTest: XCTestCase { - func testWithoutPrefix() { expect("prefixAbc".without(prefix: "prefix")).to(equal("Abc")) expect("prefix".without(prefix: "prefix")).to(equal("")) diff --git a/Commons/Tests/CommonsTests/SwiftCommonsTest.swift b/Commons/Tests/CommonsTests/SwiftCommonsTest.swift index e9f245d3..3b7b09c1 100644 --- a/Commons/Tests/CommonsTests/SwiftCommonsTest.swift +++ b/Commons/Tests/CommonsTests/SwiftCommonsTest.swift @@ -4,19 +4,17 @@ */ import Cocoa -import XCTest import Nimble +import XCTest @testable import Commons struct Dummy { - var value: Int var marker: Bool } class ArraySliceTest: XCTestCase { - func testArraySliceGroup1() { let grouped = [ Dummy(value: 0, marker: true), @@ -26,7 +24,7 @@ class ArraySliceTest: XCTestCase { Dummy(value: 2, marker: false), Dummy(value: 3, marker: false), - ][1...3].groupedRanges { i, element in element.marker } + ][1...3].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -45,7 +43,7 @@ class ArraySliceTest: XCTestCase { Dummy(value: 3, marker: true), Dummy(value: 3, marker: true), - ][1...3].groupedRanges { i, element in element.marker } + ][1...3].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -63,11 +61,11 @@ class ArraySliceTest: XCTestCase { Dummy(value: 2, marker: true), Dummy(value: 3, marker: true), - ][1...2].groupedRanges { i, element in element.marker } + ][1...2].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ - 1...2 + 1...2, ] )) } @@ -83,7 +81,7 @@ class ArraySliceTest: XCTestCase { Dummy(value: 1, marker: true), Dummy(value: 1, marker: true), - ][1...5].groupedRanges { i, element in element.marker } + ][1...5].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -105,7 +103,7 @@ class ArraySliceTest: XCTestCase { Dummy(value: 1, marker: true), Dummy(value: 1, marker: true), - ][1...5].groupedRanges { i, element in element.marker } + ][1...5].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -123,25 +121,24 @@ class ArraySliceTest: XCTestCase { Dummy(value: 0, marker: true), Dummy(value: 0, marker: true), - ][1...1].groupedRanges { i, element in element.marker } + ][1...1].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ - 1...1 + 1...1, ] )) } } class SwiftCommonsTest: XCTestCase { - func testArrayGroup1() { let grouped = [ Dummy(value: 0, marker: true), Dummy(value: 1, marker: false), Dummy(value: 2, marker: false), Dummy(value: 3, marker: false), - ].groupedRanges { i, element in element.marker } + ].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -157,7 +154,7 @@ class SwiftCommonsTest: XCTestCase { Dummy(value: 1, marker: false), Dummy(value: 2, marker: false), Dummy(value: 3, marker: true), - ].groupedRanges { i, element in element.marker } + ].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -171,11 +168,11 @@ class SwiftCommonsTest: XCTestCase { let grouped = [ Dummy(value: 0, marker: true), Dummy(value: 1, marker: true), - ].groupedRanges { i, element in element.marker } + ].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ - 0...1 + 0...1, ] )) } @@ -187,7 +184,7 @@ class SwiftCommonsTest: XCTestCase { Dummy(value: 1, marker: false), Dummy(value: 1, marker: true), Dummy(value: 1, marker: true), - ].groupedRanges { i, element in element.marker } + ].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -205,7 +202,7 @@ class SwiftCommonsTest: XCTestCase { Dummy(value: 1, marker: true), Dummy(value: 1, marker: false), Dummy(value: 1, marker: true), - ].groupedRanges { i, element in element.marker } + ].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ @@ -219,11 +216,11 @@ class SwiftCommonsTest: XCTestCase { func testArrayGroup6() { let grouped = [ Dummy(value: 0, marker: true), - ].groupedRanges { i, element in element.marker } + ].groupedRanges { _, element in element.marker } expect(grouped).to(equal( [ - 0...0 + 0...0, ] )) } diff --git a/Commons/Tests/CommonsTests/UrlCommonsTest.swift b/Commons/Tests/CommonsTests/UrlCommonsTest.swift index efe9f29f..b3850b8c 100644 --- a/Commons/Tests/CommonsTests/UrlCommonsTest.swift +++ b/Commons/Tests/CommonsTests/UrlCommonsTest.swift @@ -3,11 +3,10 @@ * See LICENSE */ -import XCTest import Nimble +import XCTest class UrlCommonsTest: XCTestCase { - func testIsDirectParent() { let parent = URL(fileURLWithPath: "/some/path") let child = URL(fileURLWithPath: "/some/path/text.txt") @@ -47,12 +46,17 @@ class UrlCommonsTest: XCTestCase { func testParent() { expect(URL(fileURLWithPath: "/some/path/").parent).to(equal(URL(fileURLWithPath: "/some/"))) - expect(URL(fileURLWithPath: "/some/path/text.txt").parent).to(equal(URL(fileURLWithPath: "/some/path/"))) + expect(URL(fileURLWithPath: "/some/path/text.txt").parent) + .to(equal(URL(fileURLWithPath: "/some/path/"))) expect(URL(fileURLWithPath: "/").parent).to(equal(URL(fileURLWithPath: "/"))) } func testIsDir() { - let resourceUrl = Bundle.module.url(forResource: "UrlCommonsTest", withExtension: "", subdirectory: "Resources")! + let resourceUrl = Bundle.module.url( + forResource: "UrlCommonsTest", + withExtension: "", + subdirectory: "Resources" + )! let hidden = resourceUrl.appendingPathComponent(".dot-hidden-file") expect(resourceUrl.isDir).to(beTrue()) @@ -60,7 +64,11 @@ class UrlCommonsTest: XCTestCase { } func testIsHidden() { - let resourceUrl = Bundle.module.url(forResource: "UrlCommonsTest", withExtension: "", subdirectory: "Resources")! + let resourceUrl = Bundle.module.url( + forResource: "UrlCommonsTest", + withExtension: "", + subdirectory: "Resources" + )! let hidden = resourceUrl.appendingPathComponent(".dot-hidden-file") expect(hidden.isHidden).to(beTrue()) @@ -68,7 +76,11 @@ class UrlCommonsTest: XCTestCase { } func testIsPackage() { - let resourceUrl = Bundle.module.url(forResource: "UrlCommonsTest", withExtension: "", subdirectory: "Resources")! + let resourceUrl = Bundle.module.url( + forResource: "UrlCommonsTest", + withExtension: "", + subdirectory: "Resources" + )! let package = resourceUrl.appendingPathComponent("dummy.rtfd") expect(package.isPackage).to(beTrue()) diff --git a/Commons/Tests/CommonsTests/XCTestManifests.swift b/Commons/Tests/CommonsTests/XCTestManifests.swift index 52f58835..82fa7cc4 100644 --- a/Commons/Tests/CommonsTests/XCTestManifests.swift +++ b/Commons/Tests/CommonsTests/XCTestManifests.swift @@ -1,9 +1,9 @@ import XCTest #if !canImport(ObjectiveC) -public func allTests() -> [XCTestCaseEntry] { - return [ - testCase(CommonsTests.allTests), + public func allTests() -> [XCTestCaseEntry] { + [ + testCase(CommonsTests.allTests), ] -} + } #endif diff --git a/NvimView/Sources/NvimView/ModeInfo.swift b/NvimView/Sources/NvimView/ModeInfo.swift index dc4cca4f..b78a8556 100644 --- a/NvimView/Sources/NvimView/ModeInfo.swift +++ b/NvimView/Sources/NvimView/ModeInfo.swift @@ -45,6 +45,6 @@ public struct ModeInfo: CustomStringConvertible { } public var description: String { - return "ModeInfo<\(name) (\(shortName)) shape: \(cursorShape) attr_id:\(attrId)>" + return "ModeInfo<\(name) (\(shortName)) shape: \(cursorShape) attr_id:\(String(describing: attrId))>" } } diff --git a/NvimView/Sources/NvimView/Typesetter.swift b/NvimView/Sources/NvimView/Typesetter.swift index be32ad9f..7099d1c3 100644 --- a/NvimView/Sources/NvimView/Typesetter.swift +++ b/NvimView/Sources/NvimView/Typesetter.swift @@ -43,7 +43,7 @@ final class Typesetter { var columnPosition = 0.cgf var deltaX = 0.cgf - _ = positions.withUnsafeMutableBufferPointer { positionsPtr -> Void in + positions.withUnsafeMutableBufferPointer { positionsPtr -> Void in for i in 0.. [NvimUtf16CellsRun] { if nvimUtf16Cells.isEmpty { return [] } - let utf16Chars = self.utf16Chars(from: nvimUtf16Cells) - let hasMoreThanTwoCells = nvimUtf16Cells.count >= 2 let firstCharHasSingleUnichar = nvimUtf16Cells[0].count == 1 let firstCharHasDoubleWidth = hasMoreThanTwoCells && nvimUtf16Cells[1].isEmpty