Files
SwiftLint/Source/SwiftLintFramework/Extensions/NSFileManager+SwiftLint.swift
T
JP Simard da1d0ba876 make FileManager.filesToLintAtPath(_:) compile on Linux
by addressing differences in FileManager APIs on Linux and Darwin
2016-12-11 14:04:49 -08:00

41 lines
1.3 KiB
Swift

//
// NSFileManager+SwiftLint.swift
// SwiftLint
//
// Created by JP Simard on 5/28/15.
// Copyright © 2015 Realm. All rights reserved.
//
import Foundation
extension FileManager {
internal func filesToLintAtPath(_ path: String, rootDirectory: String? = nil) -> [String] {
let rootPath = rootDirectory ?? currentDirectoryPath
let absolutePath = path.bridge()
.absolutePathRepresentation(rootDirectory: rootPath).bridge()
.standardizingPath
var isDirectoryObjC: ObjCBool = false
guard fileExists(atPath: absolutePath, isDirectory: &isDirectoryObjC) else {
return []
}
#if os(Linux)
let isDirectory = isDirectoryObjC
#else
let isDirectory = isDirectoryObjC.boolValue
#endif
if isDirectory {
do {
return try subpathsOfDirectory(atPath: absolutePath)
.map(absolutePath.bridge().appendingPathComponent).filter {
$0.bridge().isSwiftFile()
}
} catch {
fatalError("Couldn't find files in \(absolutePath): \(error)")
}
} else if absolutePath.bridge().isSwiftFile() {
return [absolutePath]
}
return []
}
}