mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
ee638ef428
* commit '20870e7ab140e39dbe426feb322e8b02c7cfc993': fix single file usage: `swiftlint lint --path File.swift` # Conflicts: # Source/SwiftLintFramework/Extensions/NSFileManager+SwiftLint.swift # Source/SwiftLintFramework/Models/Configuration.swift # Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
//
|
|
// NSFileManager+SwiftLint.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by JP Simard on 5/28/15.
|
|
// Copyright (c) 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.absolutePathRepresentation(rootDirectory: rootPath) as NSString)
|
|
.standardizingPath
|
|
var isDirectory: ObjCBool = false
|
|
guard fileExists(atPath: absolutePath, isDirectory: &isDirectory) else {
|
|
return []
|
|
}
|
|
if isDirectory.boolValue {
|
|
do {
|
|
return try subpathsOfDirectory(atPath: absolutePath)
|
|
.map((absolutePath as NSString).appendingPathComponent).filter {
|
|
$0.isSwiftFile()
|
|
}
|
|
} catch {
|
|
fatalError("Couldn't find files in \(absolutePath): \(error)")
|
|
}
|
|
} else if absolutePath.isSwiftFile() {
|
|
return [absolutePath]
|
|
}
|
|
return []
|
|
}
|
|
}
|