1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-09-11 17:15:34 +03:00

Fix some of swiftlint msgs

This commit is contained in:
Tae Won Ha 2020-12-25 21:59:35 +01:00
parent 76e390d85d
commit cb5ea8b7a9
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 14 additions and 36 deletions

View File

@ -87,7 +87,10 @@ public extension NSColor {
public extension NSImage {
func tinting(with color: NSColor) -> NSImage {
// swiftlint:disable force_cast
// Copy should be safe to force cast.
let result = self.copy() as! NSImage
// swiftlint:enable force_cast
result.lockFocus()
color.set()
@ -132,7 +135,6 @@ 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 rightCommand = NSEvent.ModifierFlags(rawValue: 0x100010)
@ -141,5 +143,4 @@ public extension NSEvent.ModifierFlags {
static let leftOption = NSEvent.ModifierFlags(rawValue: 0x080020)
static let rightControl = NSEvent.ModifierFlags(rawValue: 0x042000)
static let leftControl = NSEvent.ModifierFlags(rawValue: 0x040001)
// @formatter:on
}

View File

@ -14,11 +14,3 @@ public extension CGSize {
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
}
}

View File

@ -22,46 +22,35 @@ public final class FileUtils {
]
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
return []
}
) else { return [] }
return childUrls
}
public static func fileExists(at url: URL) -> Bool {
guard url.isFileURL else {
return false
}
guard url.isFileURL else { return false }
let path = url.path
return self.fileManager.fileExists(atPath: path)
}
public static func commonParent(of urls: [URL]) -> URL {
guard urls.count > 0 else {
return URL(fileURLWithPath: "/", isDirectory: true)
}
guard urls.count > 0 else { return URL(fileURLWithPath: "/", isDirectory: true) }
let pathComps = urls.map { $0.deletingLastPathComponent().pathComponents }
let min = pathComps.map(\.count).min()!
let pathCompsOnlyMin = pathComps.map { $0[0..<min] }
let commonIdx = (0..<min).reversed().reduce(min - 1) { result, idx in
if Set(pathCompsOnlyMin.map { $0[idx] }).count > 1 {
return idx - 1
} else {
return result
}
if Set(pathCompsOnlyMin.map { $0[idx] }).count > 1 { return idx - 1 }
else { return result }
}
let result = pathCompsOnlyMin[0]
@ -70,14 +59,10 @@ public final class FileUtils {
return possibleParent.isDir ? possibleParent : possibleParent.parent
}
public static func icon(forType type: String) -> NSImage {
workspace.icon(forFileType: type)
}
public static func icon(forType type: String) -> NSImage { workspace.icon(forFileType: type) }
public static func icon(forUrl url: URL) -> NSImage? {
if let cached = iconsCache.object(forKey: url as NSURL) {
return cached
}
if let cached = iconsCache.object(forKey: url as NSURL) { return cached }
let path = url.path
let icon = workspace.icon(forFile: path)

View File

@ -160,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: How to error handle?
log.error("ERROR while getting \(key): \(error)")
return false
}