Files
SwiftLint/Source/SwiftLintFramework/Extensions/Configuration+LintableFiles.swift
T
JP Simard 3a32d6b479 Speed up reading cached results by about 200%
also slightly speed up writing to the cache.

For example, on the Lyft codebase with 1,500 Swift files:

```bash
$ time swiftlint lint --quiet
swiftlint --quiet  3.53s user 0.27s system 388% cpu 0.979 total
$ rm -rf ~/Library/Caches/SwiftLint && time swiftlint lint --quiet
swiftlint --quiet  35.20s user 1.22s system 371% cpu 9.806 total
$ time swiftlint lint --quiet
swiftlint lint --quiet  0.90s user 0.13s system 218% cpu 0.472 total
$ rm -rf ~/Library/Caches/SwiftLint && time swiftlint lint --quiet
swiftlint lint --quiet  31.78s user 1.18s system 360% cpu 9.146 total
```
2017-10-19 23:17:01 -07:00

35 lines
1.1 KiB
Swift

//
// Configuration+LintableFiles.swift
// SwiftLint
//
// Created by JP Simard on 7/17/17.
// Copyright © 2017 Realm. All rights reserved.
//
import Foundation
import SourceKittenFramework
extension Configuration {
public func lintableFiles(inPath path: String) -> [File] {
return lintablePaths(inPath: path).flatMap(File.init(pathDeferringReading:))
}
internal func lintablePaths(inPath path: String,
fileManager: LintableFileManager = FileManager.default) -> [String] {
// If path is a file, skip filtering with excluded/included paths
if path.isFile {
return [path]
}
let pathsForPath = included.isEmpty ? fileManager.filesToLint(inPath: path, rootDirectory: nil) : []
let excludedPaths = excluded.flatMap {
fileManager.filesToLint(inPath: $0, rootDirectory: rootPath)
}
let includedPaths = included.flatMap {
fileManager.filesToLint(inPath: $0, rootDirectory: rootPath)
}
return (pathsForPath + includedPaths).filter {
!excludedPaths.contains($0)
}
}
}